Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Change Breadcrumb Home Text

Just downloaded Vanilla for the first time (2.1.1) and I am trying to put a custom theme together. Can anyone tell me if it is possible to change the text used for the start of the trail (i.e. "Home") to something else (e.g. "Forums")? I am trying to theme the forums so that they look like part of my main site and while the breadcrumb start may be "Home" for the forum side of things it isn't "Home" for the entire website (the forums will reside at domain.com/support/forums for example).

Also what is the best source of documentation for all things Vanilla? I have found the Vanilla Forums Theme Guide PDF which is a good start and http://vanillaforums.org/docs, are they (along with these forums) the places to go?

Thanks

Alan

Best Answer

  • hgtonighthgtonight MVP
    edited September 2014 Answer ✓

    Breadcrumbs are set at the controller level. If the homelink is not specified, it will default to the translated version of 'Home'.

    If you are creating a modified theme, I would suggest creating a custom breadcrumb smarty plugin that adds the upper level link(s) and calls Gdn_Theme::Breadcrumbs() with homelink set to false.

    Something like the following will set you up right:

    <?php if (!defined('APPLICATION')) exit();
    /**
     * Render a breadcrumb trail for the user based on the page they are on, keeping in mind the level of Vanilla as a whole.
     */
    function smarty_function_custombreadcrumbs($Params, &$Smarty) {
      $Breadcrumbs = $Smarty->Controller->Data('Breadcrumbs');
      if (!is_array($Breadcrumbs)) {
        $Breadcrumbs = array();
      }
    
      // Add the forums link to the crumbs
      array_unshift($Breadcrumbs, array('Name' => T('Forums'), 'Url' => '/'));
    
      // Add the home page link to the crumbs
      array_unshift($Breadcrumbs, array('Name' => T('Home'), 'Url' => 'http://www.example.com/'));
    
      return Gdn_Theme::Breadcrumbs($Breadcrumbs, FALSE);
    }
    

    You will need to add this as a Smarty plugin via your themehooks file. Check out this discussion for more information: http://vanillaforums.org/discussion/27767/how-to-create-custom-smarty-functions

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Answers

  • hgtonighthgtonight MVP
    edited September 2014 Answer ✓

    Breadcrumbs are set at the controller level. If the homelink is not specified, it will default to the translated version of 'Home'.

    If you are creating a modified theme, I would suggest creating a custom breadcrumb smarty plugin that adds the upper level link(s) and calls Gdn_Theme::Breadcrumbs() with homelink set to false.

    Something like the following will set you up right:

    <?php if (!defined('APPLICATION')) exit();
    /**
     * Render a breadcrumb trail for the user based on the page they are on, keeping in mind the level of Vanilla as a whole.
     */
    function smarty_function_custombreadcrumbs($Params, &$Smarty) {
      $Breadcrumbs = $Smarty->Controller->Data('Breadcrumbs');
      if (!is_array($Breadcrumbs)) {
        $Breadcrumbs = array();
      }
    
      // Add the forums link to the crumbs
      array_unshift($Breadcrumbs, array('Name' => T('Forums'), 'Url' => '/'));
    
      // Add the home page link to the crumbs
      array_unshift($Breadcrumbs, array('Name' => T('Home'), 'Url' => 'http://www.example.com/'));
    
      return Gdn_Theme::Breadcrumbs($Breadcrumbs, FALSE);
    }
    

    You will need to add this as a Smarty plugin via your themehooks file. Check out this discussion for more information: http://vanillaforums.org/discussion/27767/how-to-create-custom-smarty-functions

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Wow thanks for such a comprehensive reply. It works a treat!

    Alan

  • @alan0209 said:
    Wow thanks for such a comprehensive reply. It works a treat!

    Alan

    I didn't actually test it, so I am glad it works :D

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • You can also build your own custom Breadcrumb by iterating over the smarty $Breadcrumbs var in your template instead of using the preformatted one. This is how I did it, by reusing the formatting already in place on the main site:

    <div class="rcrumbs"> <ul> <li> <a class="icon-home" href="{$Mainsite}">​</a> <span class="divider icon-angle-right" aria-hidden="true"></span> </li> <li> <a href="/" {if count($Breadcrumbs) == 0}class="active"{/if}>Forum</a> {if count($Breadcrumbs) > 0}<span class="divider icon-angle-right" aria-hidden="true"></span>{/if} </li> {foreach item=crumb from=$Breadcrumbs name=crumbloop} <li> <a href="{$crumb.Url}" {if $smarty.foreach.crumbloop.last}class="active"{/if}>{$crumb.Name}</a> {if !$smarty.foreach.crumbloop.last} <span class="divider icon-angle-right" aria-hidden="true"></span> {/if} </li> {/foreach} </ul> </div>

Sign In or Register to comment.