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
-
hgtonight MVP
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
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.
1
Answers
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:
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
I didn't actually test it, so I am glad it works
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>