Skip to content

Instantly share code, notes, and snippets.

@low
Created September 10, 2012 07:14
Show Gist options
  • Save low/3689381 to your computer and use it in GitHub Desktop.
Save low/3689381 to your computer and use it in GitHub Desktop.
Avoid using a tag as parameter value for another tag

Avoid using a tag as parameter value for another tag in ExpressionEngine

Instead of this:

{exp:channel:entries param="{exp:some:plugin}"}
	...
{/exp:channel:entries}

Either use an embed, like this:

{embed="channel/entries" value="{exp:some:plugin}"}

{!-- And the embedded template: --}

{exp:channel:entries param="{embed:value}"}
	...
{/exp:channel:entries}

Or use the plugin as a tag pair (if supported), like this:

{exp:some:plugin parse="inward"}
	{exp:channel:entries param="{plugin_value}"}
		...
	{/exp:channel:entries}
{/exp:some:plugin}

Or add your own suggestions below.

@croxton
Copy link

croxton commented Sep 11, 2012

You don't say why it's bad to pass a tag as a parameter, so here goes:

  • you need to use parse="inward" for it to work at all. That makes EE create a new instance of the template parser to parse each parameter, whether it's the parameter containing your tag or not. More parameters = more overhead.
  • if your passed tag outputs a quote character or a line break, the EE parser will choke.
  • sometimes EE will choke if the parent tag parameters are separated onto new lines when using parse="inward"

Despite these caveats, I still think it's a useful technique for certain things and has far less overhead than an embed.

@low
Copy link
Author

low commented Sep 11, 2012

@jeromecoupe: EE provides a method for add-on devs to easily parse variables. But that method will automatically add {count}, {total_results} and {switch} to the mix. That's why there's conflicts. Not much you can do about that without getting complicated.

@croxton: The main reason why it's bad, is that it will not work in all cases. It might work in some, but inconsistency is a big pain to explain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment