[support] More elegant way to breadcrumb prior to page render

Jeff Greenberg listmail.ayendesigns at gmail.com
Sun Mar 3 21:53:39 UTC 2013


I'm posting this here instead of the theme list because even though this
would typically be needed in a theme, it's not about theming, per se.

I struggled [way too long] today to generate a full category breadcrumb.
Yes, I know, this type of thing has been asked and answered ad nauseum.
The difference here is that the point at which I need the breadcrumb (eg
grandparent category / parent category / category) is in a field template
for a field that appears in the node display ... so long before $breadcrumb
becomes available during the page render.

What I ended up with is the following. I do plan on moving the code, so no
need to flame me on having it in the template. :-)  I'd like to know if
there's an easier way to do it ... "Oh, you could have just called blah
blah" ... I promise not to cry... much.

    <?php $parents =
taxonomy_get_parents($variables['element']['#object']->field_product_category['und'][0]['tid']);
?>
    <?php $breadcrumb = drupal_get_breadcrumb(); ?>
    <?php foreach($parents as $parent): ?>
      <?php $breadcrumb[] = $parent->name; ?>
    <?php endforeach; ?>
    <?php $breadcrumb[] =
$variables['element']['#object']->field_product_category['und'][0]['taxonomy_term']->name;
?>
    <?php print theme('breadcrumb', array('breadcrumb'=>$breadcrumb)); ?>



-- 
---
drupal.org/user/367108
linkedin.com/in/jeffrgreenberg
accidentalcoder.com / ayendesigns.com
@accidentalcoder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20130303/1dbb6357/attachment.html 


More information about the support mailing list