1

I have a plugin that allows you to set and store cookies using EE tags (so you don't have to enable PHP in your templates).

Unfortunately, I can't get the tag to parse the cookie value within a channel tag:

{exp:channel:entries channel="misc{exp:cookie:retrieve name="exp_lang"}"}

Any ideas?

5

It turns out that the answer was to add a "random" paramater to the plugin tag, in combination with parse="inward".

From EllisLab: "The random is sort of a hidden trick that is handy in very specific circumstances. Without it, duplicate plugins get replaced by some placeholder text so that the plugin is only run once- and then the content flips into where the placeholder text is. But the way parse order works- if you're using one of those plugins as a parameter, it ends up treating the placeholder string as the parameter value. And basically just does not work. Random causes it to not put in the placeholder text."

I also found out that you want to use single quotes inside the plugin tag.

So this works:

{exp:channel:entries parse="inward" channel="misc{exp:cookie:retrieve name='exp_lang' random}"}
| improve this answer | |
  • Unfortunately this works perfectly. I had hoped EE had fixed up the parsing issues :( – Bradley Flood May 4 '15 at 6:53
4

This is a parse order issue - your Channel Entries tag is being parsed before your custom plugin tag, so you're actually passing misc{exp:cookie:retrieve name="exp_lang"} as the channel parameter.

What you need to do is turn your plugin into a tag pair, so it works like this:

{exp:cookie:retrieve name="exp_lang" parse="inward"}
    {exp:channel:entries channel="misc{exp_lang}"}
    ...
    {/exp:channel:entries}
{/exp:cookie:retrieve}

In your plugin you'd do something like this:

$vars = array('exp_lang' => 'en');
return $this->EE->TMPL->parse_variables_row($this->EE->TMPL->tagdata, $vars);
| improve this answer | |
  • I saw that in the template debugger the first time I tried it. Unfortunately, the parse="inward" parameter still doesn't seem to be appending the channel name properly (although it does load from the "misc" channel). It's supposed to add the language code (_es, _de, etc.) to the channel name, so that it retrieves the content from the appropriate translated channel (misc_es, misc_de, etc.). – Ty Morton Jun 18 '13 at 7:34
  • Did you alter the plugin internals so that it will work as a tag pair? That is the key. – Derek Hogue Jun 18 '13 at 12:42
  • I'm not versed enough in plugin development, unfortunately. I'm looking into it, now, though. Thanks for the advice. – Ty Morton Jun 18 '13 at 14:45
0

The value inward can be used to parse data inside an opening variable too.

Try this:

{exp:channel:entries channel="misc{exp:cookie:retrieve name='exp_lang'}" parse="inward"}
    [...]
{/exp:channel:entries}
| improve this answer | |
0

As has previously been stated, you're running into a classic parse order issue. If you're not already familiar with Low's Parse Order PDF, I would recommend printing it and bookmarking it. It can be really useful until you've managed to memorize the order. http://loweblog.com/downloads/ee-parse-order.pdf

Additionally, you could create an extension to conditionally set the value (currently being set by your plugin) of a global variable. That of course would depend on your cookie name being consistent for this usage.

| improve this answer | |
  • Thanks for the link. I've used the parse="inward" parameter, and it doesn't seem to be resolving the situation. – Ty Morton Jun 18 '13 at 7:30
  • Have you considered using Stash to stash away the value of the cookie? You'll still have to take note of parse order while working with Stash but I'm sure you could make it happen. – Tyler Willingham Jun 20 '13 at 19:10
  • Oh, also: you don't necessarily need to use Stash, you could just pass the value along to the current template by way of an Embed Variable. – Tyler Willingham Jun 20 '13 at 19:12

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.