1

I'm wanting to access a variable from the series channel called {custom_series_field}, but I need to access that variable within the reverse related entries tag. Currently, this code doesn't parse the {custom_series_field} variable inside of the reverse entries tag.

Here is the sample code:

{exp:channel:entries channel='series' status='open|hidden' url_title='{segment_2}' dynamic='off'}
  {custom_series_field}

  {reverse_related_entries status='open|hidden' orderby='date' sort="desc" limit='1'}
    Reverse related content here
    {custom_series_field}
  {/reverse_related_entries}
{/exp:channel:entries}

I know you can do this with playa, but we're not ready to update quite yet. Is it possible to access a channel variable here?

2
  • When you try it, does it work? Nov 27 '12 at 19:17
  • When I run my sample code the variable inside the reverse_related_entries tag literally displays "{custom_series_field}"
    – Jon Horton
    Nov 27 '12 at 21:12
3

Yes, just use Stash (you're using it already right, like everyone else? ;-))

{exp:channel:entries channel='series' status='open|hidden' url_title='{segment_2}' dynamic='off'}
  {exp:stash:set name="parent_title"}{title}{/exp:stash:set}
  {reverse_related_entries status='open|hidden' orderby='date' sort="desc" limit='1'}
    Reverse related content here
    {exp:stash:get name="parent_title"}
  {/reverse_related_entries}
{/exp:channel:entries}
2
  • Would stash:get parse later than the reverse_related_entries tag pair? I'm curious myself. I've had the odd issue using set and get in the same template. Nov 27 '12 at 17:37
  • I haven't tested this, but I used to do it all the time using String, where it's documented here, and should theoretically work the same as Stash: emarketsouth.com/add-ons/string-plugin/examples/… Nov 27 '12 at 17:39
3

Unfortunately you can't. You will have to pass the entry_id or url_title to an embed to get a custom field from that channel. See Docs for more info

6
  • The docs actually say the opposite of this. It specifically is using a custom field named {body} in the example you linked to. Nov 27 '12 at 17:20
  • But if that really doesn't work for some reason (we have been using Playa for a long time so I can't recall), see my answer providing a tag named More Entries that will do this. Nov 27 '12 at 17:23
  • It won't hurt to try-give it a shot Jon. It's been a while since I used the native relationships.
    – Siebird
    Nov 27 '12 at 17:26
  • I think the issue possibly is linking to the same channel? That would still not work properly (even with my plugin currently) because as soon as the first tag sees it's fields, it will replace all of them and not give the inner {reverse_related_entries} or more_entries tag a chance to parse those fields. Nov 27 '12 at 17:45
  • I may not have been clear enough in my initial post. I want to access a variable from the channel tag, not a variable from the reverse related entry. Does that make sense?
    – Jon Horton
    Nov 27 '12 at 18:04
1

I don't know that this should be needed as the docs for Reverse Related Entries certainly show it using custom fields just fine... but, you can use this quick plugin, More Entries, I just put up to do this. It basically is a {exp:channel:entries} tag with a different name, allowing you to call the tag within an existing {exp:channel:entries} tag.

Note that as pointed out in the comments, it is still not a good idea to run database queries in a loop that is itself a result of a database query because the performance of the nested loops will be very bad. That said, if you're going to use an expensive embed and do it anyway, you might as well skip the embed and just run the query directly, which this plugin allows you to do.

{exp:channel:entries channel="series" status="open|hidden" url_title="{segment_2}" dynamic="off"}
    {reverse_related_entries status='open|hidden' orderby='date' sort="desc" limit='1'}
        {exp:more_entries entry_id="{entry_id}" status="open|hidden" dynamic="off"}
            {whatever_field_here}
        {/exp:more_entries}
    {/reverse_related_entries}
{/exp:channel:entries}

Note that this still won't let you parse the same channel in the nested more_entries loop because the outer {exp:channel:entries} will replace all of the fields before the plugin gets a chance to do it. I'll work on a version that works around this - it should be possible - but you'd need to still use Stash or an embed if you need to relate entries to their same channel.

2
  • What is the advantage of doing this versus embedding a real channel:entries tag? I know you're not supposed to ever do that (and with good reason), but surely all those good reasons not to do it would apply equally to embedding a clone of the channel entries tag? Nov 27 '12 at 17:35
  • Yes they do apply. It is not a good idea to run database queries in a loop that is itself a result of a database query - the performance of the combined code is really bad in many cases. That said, if you're going to use an expensive embed and do it anyway, you might as well skip the embed and just run the query directly. Nov 27 '12 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.