[Guide] Explanation of Breadcrumbs

Status
Not open for further replies.

Heretic121

OMG Member
Joined
Sep 24, 2010
Messages
446
Now when I started off, I had no idea what on earth "breadcrumbs" are or what to expect. So for those of you that don't know: It's the list of links which looks like arrows, or as my missus just said "They're tabs :s"
breadcrumbs.png

Those (See image) are breadcrumbs.

Breadcrumbs are named so because they're there to "help you find your way back" (i.e. you leave a trail of breadcrumbs to follow it back to where you were).

Now to create breadcrumbs you will need to add them through your AdminCP (Administrative Control Panel) then go to Appearance and from there select templates. To add breadcrumbs it's a simple case of adding:
Code:
<xen:navigation>
  <xen:breadcrumb href="http://www.thisisalink.com">Text</xen:breadcrumb>
</xen:navigation>
I've tried adding a foreach into the mix, like so:
Code:
<xen:navigation>
  <xen:foreach loop="{$links}" value="$link">
    <xen:breadcrumb href="$link[1]">$link[0]</xen:breadcrumb>
  </xen:foreach>
</xen:navigation>
But it would appear XenForo doesn't like that. I also tried loading the breadcrumb using PHP and returning the value into the template with a variable, but that didn't work either.
So it would appear that we're stuck with semi-static breadcrumbs, but I'm not entirely sure as you can load breadcrumbs using PHP but it's just not very ... clean.
[]
EDIT:
Thanks to Cezz for his help with creating breadcrumbs using PHP. It would appear that it is indeed possible to create multiple links using PHP. Simply using the follow code should do it:
Code:
<xen:navigation>
  <xen:breadcrumb source="$links" />
</xen:navigation>
Then you pass the array of links you want, renaming $links to whatever string you have as your "key". So if your array of links was called "breadcrumbs" like this:
PHP:
$Array = array (
    'breadCrumbs' => etc, etc... // Array of links.
);
Then you would use $breadCrumbs instead of $links.
[]
Even if you can't add multiple crumbs using PHP, or a foreach in XenForo, you can add them manually like so:
Code:
<xen:navigation>
  <xen:breadcrumb href="http://www.thisisalink.com">Text</xen:breadcrumb>
  <xen:breadcrumb href="http://www.thisisaotherlink.com">Second Text</xen:breadcrumb>
</xen:navigation>
This would create two crumbs for one page. Using this you can as many as you need to add, but please only add crumbs if your user needs them and not if you just fancy having some extra.
You can also call phrases into your breadcrumbs. Like so:
Code:
<xen:navigation>
  <xen:breadcrumb href="http://www.thisisalink.com">{xen:phrase home}</xen:breadcrumb>
</xen:navigation>
This would make a breadcrumb and the label for it would be the one that you have saved for the phrase home, which is also the same phrase used for the first breadcrumb.

I think that's about all the explanation you'll need for this really, but if you have any questions, fire away and I'll attempt to answer them to the best of my knowledge.
 

Floris

I'm just me :) Hi.
Staff member
Joined
Jan 1, 2001
Messages
60,098
It's a good start, and not too complex to newcomers. I think it's just fine :)
 

Cezz

OMG Member
Joined
Sep 24, 2010
Messages
581
Awesome... one question though shouldn't

HTML:
<xen:navigation>
  <xen:foreach loop="{$links}" value="$link">
     <xen:breadcrumb href="$link[1]">$link[0]</xen:breadcrumb>
   </xen:foreach>
 </xen:navigation>

be

HTML:
<xen:navigation>
<xen:foreach loop="$links" value="$link">
     <xen:breadcrumb href="{$link.1}">{$link.0}</xen:breadcrumb>
   </xen:foreach>
 </xen:navigation>

which would be why you had problems.
 

Heretic121

OMG Member
Joined
Sep 24, 2010
Messages
446
I think I tried both approaches but both of those are wrong. If you look at my explanation of XenForo arrays: $link[0] and $link[1] should actually be $link.0 and $link.1 :)
But you're correct, it should be {$link.1} and {$link.0} however it still won't work, XenForo doesn't seem to like it apparently :(

EDIT: Saving fails with this error message:
Code:
The following templates contained errors and were not saved:   heretech121: 1)	Line 3: Invalid data found in navigation tag.
 

Cezz

OMG Member
Joined
Sep 24, 2010
Messages
581
I think I tried both approaches but both of those are wrong. If you look at my explanation of XenForo arrays: $link[0] and $link[1] should actually be $link.0 and $link.1 :)
But you're correct, it should be {$link.1} and {$link.0} however it still won't work, XenForo doesn't seem to like it apparently :(

EDIT: Saving fails with this error message:
Code:
The following templates contained errors and were not saved:   heretech121: 1)	Line 3: Invalid data found in navigation tag.


What about

HTML:
<xen:navigation>
	<xen:breadcrumb source="$links" />
</xen:navigation>

What is the var_dump or $links how is it formatted?
 

Heretic121

OMG Member
Joined
Sep 24, 2010
Messages
446
Yep, that seems to have fixed it. Nicely done Cezz :)

I'll update the guide accordingly ;)
 
Status
Not open for further replies.
Top