Pass Variable to Template

Is there a method to pass a variable to a L&L template via the template shortcode (like passing variables to standard shortcodes)? I am trying to pass a post_id to template to then use in the loop parameters within the template.


1 Like

Hello, thank you for the question.

Currently there’s no direct way to pass variables to a template via the shortcode - but that does sound useful. Probably the simplest way to support this is by making shortcode attributes available in the template as variables. Something like:

[template id=1 post_id=123]

…which could be used from the template like:

<Get post_id />

…or more practically:

<Loop type=post id="{Get post_id}">

OK, I’ve made a note to implement this, and will let you know when it’s ready.

1 Like

Awesome. And that is exactly what I was referring to and fits my use case exactly.


1 Like

Hello - In the newest version, the Template tag (and shortcode) passes its attributes as “local variables” to the template.

Local variables is a new feature also, briefly documented here:

Basically, they exist only within a template post (or file) - so they don’t affect other templates that use the same variable names. It works with the Get and Set tag, using the local attribute.

So, if the shortcode is:

[template id=1 post_id=123]

…the variable can be used like:

<Get local=post_id />

<Loop type=post id="{Get local=post_id}">

I’d love to hear if that works for you.