Page 1 of 1

Breadcrumb trail, how do I exclude the freetag plugin

Posted: Mon Oct 30, 2006 8:44 pm
by carl_galloway
I want to add some extra intelligence to my breadcrumb trail to exclude the freetag plugin. What happen is that my trail works perfectly with blog entries, static pages and the contact form plugin. When a user clicks a tag, the freetag plugin sets $head_subtitle, but doesn't set $head_title, so I end up with the 'Entries tagged as ...' appearing in the space where the breadcrumb is supposed to be, and then immediately below this I get the cloud header 'Tags related to tag ...', which looks a bit silly.

I've tried testing for $plugin_freetag_name at the section where the $head-subtitle is called, but this doesn't work. Any ideas?

Code: Select all

<div class="breadcrumb">
{if $startpage}{else}<a href="{$serendipityBaseURL}">{$CONST.HOMEPAGE} </a>{/if}
{if $head_title && !$entry.title | $head_title != $entry.title}
 {if $entry.title}»{/if} {$category.category_name}
{elseif $head_title && $entry.title}
 {if $category.category_name}
   » <a href="{$category.category_link}" title="{$category.category_description}"> {$category.category_name}</a>
{/if}
 {if $entry.title == $head_title}
   » {$entry.title|truncate:40:" ...":true}
 {/if}
{elseif $head_subtitle} {if $plugin_freetag_name}{else} » {$head_subtitle}{/if}
{/if}
 {foreach name="crumbs" from=$staticpage_navigation.crumbs item="crumb"}
» <a href="{$crumb.link}">{$crumb.name|@escape}</a>
  {/foreach}
{if $plugin_contactform_name}» <a href="#">{$plugin_contactform_name}</a>{/if}
</div>

Posted: Thu Nov 02, 2006 9:33 pm
by judebert
Interesting. The {if} logic is a little hard to follow; let me use this article as a scratchpad.

If this isn't the startpage, start with a link to the startpage.

If I've got a head but no entry title, or they're different, print the category;
OTHERWISE, if there's both a head and entry, throw them in;
OTHERWISE, if there's a subtitle,
if the freetag plugin isn't enabled, print it;
so much for that part.

Print all the defined breadcrumbs.

Print contact information.


First off, I think you need to use || instead of | for "or". Perhaps that's just a typo (or maybe I'm wrong). But that shouldn't effect the tags.

Without a head title, we're not going to get anything but the startpage link before the subtitle. I assume the freetag plugin sets the subtitle to "Entries tagged as ...". What would you like to appear there?

It looks like $plugin_freetag_name doesn't actually specify that the freetag plugin is working. I checked the plugin, and I don't see it setting anything like that, so we'll have to think of something else.

Looks like the plugin provides raw data. That would imply that $head_title never gets set (since the plugin doesn't appear to do it). Nor would $entry.title.

With that in mind, how about this:

Code: Select all

{elseif $head_subtitle && ($head_title || $entry.title)}
» {$head_subtitle}
That should exclude the freetag, but other pages should set SOMETHING, so they'll get the subtitle.

Sorry for the rambling; hope this helps.

Posted: Fri Nov 03, 2006 5:46 am
by carl_galloway
hmmm, that didn't seem to work, sorry Jude, it still produces exaclty the same result. I cleared my template cache just to be sure. Any other ideas?

Carl

Posted: Tue Nov 07, 2006 9:33 pm
by judebert
Whoa. Could you try changing it to output all the variables, just for testing?

Code: Select all

» {$head_subtitle}/{$entry.title}/{$head_title}
I didn't see the plugin setting either of those, but maybe one gets set in the code somewhere. If so, I'd like to know what it gets set to.

Posted: Tue Nov 07, 2006 9:34 pm
by judebert
Oooh, wait a minute! According to the Smarty {if} documentation, we should try isset($head_title) instead of just $head_title.

Posted: Wed Nov 08, 2006 3:12 am
by carl_galloway
Jude, following this code change;

Code: Select all

» {$head_subtitle}/{$entry.title}/{$head_title} 
I get the 'entries tagged as...' for $head_subtitle
I get the title of the last entry for the tag being requested in $entry_title
and $head_title is empty

Following the instructions to use the isset generates a fatal error, perhaps I need more instruction son how to format this line.

Posted: Wed Nov 08, 2006 3:51 pm
by judebert
Ah-ha! So $entry.title is actually set when you're on the freetag page. That explains why we're getting into that little piece of code.

Let's try this:

Code: Select all

{elseif $head_subtitle && $head_title} » {$head_subtitle}{/if}
{/if} 
Since the freetag page isn't setting a $head_title, this should only print the subtitle when the subtitle exists and the title doesn't. That excludes the freetag page.

According to the <a href="http://smarty.php.net/manual/en/languag ... hp">Smarty {if} documentation</a>, the more correct version would be:

Code: Select all

{elseif isset($head_subtitle) && isset($head_title)}
 » {$head_subtitle}{/if}
{/if} 
The only problem I envision is that $head_title might be set, but empty. in that case, we'd have to extend the comparison even more:

Code: Select all

{elseif $head_subtitle && isset($head_title) && $head_title != ''}
Working this problem has actually helped get me in the proper frame of mind for programming at work. Let me know if this works.

Posted: Wed Nov 08, 2006 5:16 pm
by carl_galloway
Genius!

And for anyone watching this thread who wants to implement a breadcrumb trail in their template, here is the complete code which creates a breadcrumb from the homepage to the entry, and also creates a breadcrumb for static pages, and also works with the contact form plugin, and now, thanks to Jude, excludes the freetag plugin because the freetag plugin already has its own formatting.

Code: Select all

<div class="breadcrumb">
    {if $startpage}{else}<a href="{$serendipityBaseURL}">{$CONST.HOMEPAGE}</a>{/if}
    {if $head_title && !$entry.title | $head_title != $entry.title}
      {if $entry.title}»{/if} {$category.category_name}
    {elseif $head_title && $entry.title}
	{if $category.category_name}
      » <a href="{$category.category_link}" title="{$category.category_description}">{$category.category_name}</a>
	{/if}
      {if $entry.title == $head_title}
        » {$entry.title|truncate:40:" ...":true}
      {/if}
    {elseif $head_subtitle && isset($head_title) && $head_title != ''}
      » {$head_subtitle}
    {/if}
     {foreach name="crumbs" from=$staticpage_navigation.crumbs item="crumb"}
	» <a href="{$crumb.link}">{$crumb.name|@escape}</a>
    {/foreach}
	{if $plugin_contactform_name}» <a href="#">{$plugin_contactform_name}</a>{/if}
</div>
In this example the breadcrumb is not visible at all when the user is on the startpage, but this is easily changed by editing the first line so that the complete breadcrumb looks like this;

Code: Select all

<div class="breadcrumb">
    <a href="{$serendipityBaseURL}">{$CONST.HOMEPAGE}</a>
    {if $head_title && !$entry.title | $head_title != $entry.title}
      {if $entry.title}»{/if} {$category.category_name}
    {elseif $head_title && $entry.title}
	{if $category.category_name}
      » <a href="{$category.category_link}" title="{$category.category_description}">{$category.category_name}</a>
	{/if}
      {if $entry.title == $head_title}
        » {$entry.title|truncate:40:" ...":true}
      {/if}
    {elseif $head_subtitle && isset($head_title) && $head_title != ''}
      » {$head_subtitle}
    {/if}
     {foreach name="crumbs" from=$staticpage_navigation.crumbs item="crumb"}
	» <a href="{$crumb.link}">{$crumb.name|@escape}</a>
    {/foreach}
	{if $plugin_contactform_name}» <a href="#">{$plugin_contactform_name}</a>{/if}
</div>
Carl

Re: Breadcrumb trail, how do I exclude the freetag plugin

Posted: Sun May 02, 2010 10:51 am
by yellowled
HiCotN wrote:Gosh, I hate to even ask this, but what file does the code go into too accomplish this?
It's most likely you want to insert this at a suitable position in your template's index.tpl.

YL