3

I've written a custom plugin which I call repeatedly (via a channel:entries tag) to store a list of entries in an array. (BTW, you have to set up a separate singleton class to do that, as the plug-in object gets re-instantiated from scratch every time it's called from the template.) So the plug-in has two functions: one to store the entry ID's (parse_home_seq), and one to return the entry we're currently looking for (get_hero), which is dictated by the value of a cookie.

I've logged extensively in the plug-in, so I know that it's returning the right ID. And yet, the second channel:entries tag always returns the same entry (while the get_hero function cycles through the entries on successive page requests). I've been banging my head against this wall all day. Here's the code:

{!-- Determine which products to use for hero --}
{exp:channel:entries channel="products" status="wide" orderby="homepage_seq_no" sort="asc"}
    {exp:ah_proc:parse_home_seq seq="{homepage_seq_no}" id="{entry_id}"}
{/exp:channel:entries}

{exp:stash:parse process="end"}
{exp:ah_proc:get_hero no_update="1"}:: {!-- for logging --}
{exp:channel:entries channel="products" entry_id="{exp:ah_proc:get_hero}" status="wide" limit="1" parse="inward"}
    {entry_id}  {!-- for logging --}
    <h1>{title}</h1>
{/exp:channel:entries}
{/exp:stash:parse}

Any help appreciated. Thank you.

1

(1) you can use the session class to store your private data in an array or object :-) http://ellislab.com/expressionengine/user-guide/development/usage/session.html#cache-array

(2) What i'ld do is wrap the whole second channel entries tag within {exp:ah_proc:get_hero} and have a simple tag {ah_proc_get_hero} which you can just be search and replaced for the chan:entries to use.

// first chan:entries tag

// second
{exp:ah_proc:get_hero parse="inward"}
  {exp:channel:entries channel="products" 
    entry_id="{ah_proc_get_hero}" status="wide" 
    limit="1"
  }
    {entry_id} <h1>{title}</h1>
  {/exp:channel:entries}
{/exp:ah_proc:get_hero}
| improve this answer | |
  • beware though, session class is not the same as session from codeigniter. the session cache is a simple php variable, only available during the duration of the request. But it helps because indeed, every plugin tag is newly instantiating the plugin class / for php 5.whatever+ you can also use a static array() property or variable inside your class :-) – GDmac Apr 15 '13 at 21:57
  • I'm only going to try the wrapping of the channel:entries. The other part works flawlessly now, so I don't want to mess with it. This whole parsing order thing is exhausting. – NotoriousWebmaster Apr 16 '13 at 1:16
  • So grateful for your help. Clever hack. – NotoriousWebmaster Apr 16 '13 at 15:29
  • another caveat is the {if no_results} tag. It is considered, by the template engine, to be from the outer tag (e.g. your plugin). One way to address this issue, is to prefix it in the template so it is not recognized as a no_results block e.g. {if prefix_no_results}. In the return_data search-replace that tag to no_results, in order to restore the no_results block for the inner tag-pair. – GDmac Apr 23 '13 at 7:02

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.