Snippet: Template logic to display fetched parent content object name

Problem

Is it possible to fetch the name of a parent folder?

Solution

I did this just today, does anyone have some ideas on how i could improve this soluton?

The solution I used was a second fetch to get the current item’s parrent name (in the main fetch’s loop).

Abreviated

{set parent_id=$cnews.parent_node_id}
{set parent=fetch('content','node', hash('node_id', $parent_id , limit, 1 , sort_by, array(array(published, false() )) )) }
{set news_category=$parent.name}
 

Complete

New Objects: <br />
<span style="font-size: 11px;">
  {set news_id=344}
  {set news_limit=4}
 
  {let recent=fetch( content, tree, hash( parent_node_id, $news_id, limit, $news_limit, 'class_filter_type', 'include', 'class_filter_array', array( 'article' ) , sort_by, array(array(published, false() )))) }
  {section show=$recent|count|gt(0)}
    {section var=cnews loop=$recent}
      {set news_title=$cnews.name}
      {set news_intro=$cnews.data_map.intro.data_text}
      {set news_date_formated=$cnews.object.current.created |datetime( 'custom', '%m/%d/%Y @ %h:%i' )}
 
      {set parent_id=$cnews.parent_node_id}
      {set parent=fetch('content','node', hash('node_id', $parent_id , limit, 1 , sort_by, array(array(published, false() ) ) )) }
      {set news_category=$parent.name}
      <div style="padding-top: 2px; padding-bottom: 8px;"><span><a href="{$cnews.url_alias}" style="color:#004A84;">{$news_title|shorten(348)}</a></span><div align="right"><span style="font-style: italic;">Added to Category: {$news_category}<br /><span style="font-size: 10px; color: grey;">Released: {$news_date_formated}</span></div></div>
    {/section}
  {/section}
 {/let}
</span>
 

Participants

  • haavard h, J-A Eberhard, and of course the inevitable kracker

References