We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Main Entry ’title’ within related_entries tag

Development and Programming

Matt Fordham's avatar
Matt Fordham
14 posts
13 years ago
Matt Fordham's avatar Matt Fordham

Hi all,

I am needing to get the title of the main entry within a nested related_entries tag. For example:

{exp:channel:entries}
  {title}
  {related_entries id="band"}
    // How can I get the parent entry's {title} here?
    {title}
  {/related_entries}

{/entries}

Any ideas???

       
Dan Decker's avatar
Dan Decker
7,338 posts
13 years ago
Dan Decker's avatar Dan Decker

Hi Matt,

Sure!

You would need a means to assign that to a variable to be used later in the template. As you can guess, the related entry’s {title} variable overrides the parent entry’s {title} variable.

Have a look at Stash - it allows for just this use of dynamic template variables.

Cheers,

       
Matt Fordham's avatar
Matt Fordham
14 posts
13 years ago
Matt Fordham's avatar Matt Fordham

Thanks! I actually tried Stash, but because I was setting the Stash variable in a loop, it was getting reset every time and then every title on the page would end up the same. Perhaps I’ll get in touch with the developer for ideas.

       
Shane Eckert's avatar
Shane Eckert
7,174 posts
13 years ago
Shane Eckert's avatar Shane Eckert

Hey Matt,

If you get in touch with the developer, that would be awesome.

Please let us know how it goes.

Cheers,

       
Matt Fordham's avatar
Matt Fordham
14 posts
13 years ago
Matt Fordham's avatar Matt Fordham

I am still having no luck with this. Could you perhaps move this thread to the general development and programming forum… or should I post there separately? Thanks!

       
Dan Decker's avatar
Dan Decker
7,338 posts
13 years ago
Dan Decker's avatar Dan Decker

Hey Matt,

Moving right away!

Thanks for posting.

Cheers,

       
lifeboatcreative's avatar
lifeboatcreative
76 posts
13 years ago
lifeboatcreative's avatar lifeboatcreative
{exp:channel:entries}
  {title}
  {related_entries id="band"}
    // How can I get the parent entry's {title} here?
    {title}
  {/related_entries}

{/entries}

Sadly, EE fails in this regard. I would use php within the the template to solve this problem. PHP parsing needs to be set on output. Not ideal, but gets the job done quickly. Maybe someday I will write an extension to help with this issue.

{exp:channel:entries}
  <?php $title = '{title}'; ?>
  {related_entries id="band"}
    // How can I get the parent entry's {title} here?
    <?php echo $title; ?>
    {title}
  {/related_entries}
{/entries}
       
Matt Fordham's avatar
Matt Fordham
14 posts
13 years ago
Matt Fordham's avatar Matt Fordham

That works, thanks!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.