Template shortcode pass variable

In a rich text field I would like to use a shortcode to output a section-template:

[bricks_template id="1234" show_text="This text shall be shown"]

But what is missing: How I can pass variables to the template. $atts[‘show_text’] or $atts isn’t working at all.

Is there a way to transfer a variable given within the shortcode?

4 Likes

I also need the same functionality.

I have a section template that uses a query loop, I would like to assign a query parameter via the short code [bricks_template id=“1234” location=“phuket”]

1 Like

Bump - can someone from the Bricks builder team at least comments on this?

Until this is solved, the work around I found was to just add custom fields to the post in question, then reference those custom fields in the template. If you need to dynamically update the template in code, updating the custom fields would accomplish the desired result?

I am also wondering why there is no solution for a problem that seems so simple.
Bricks automatically creates a Shortcode for all Templates created.
Shortcodes have $atts in WordPress, a feature that makes them useful at all.
How can I access these $atts in Bricks Builder ?

Again: Can someone from the Bricks builder team at least comments on this?

1 Like

I guess this will be solved with the new “partials” elements. But for now, it’s still in development - so we have to wait.

What you can do is: create a (PHP) shortcode yourself and call the template inside this shortcode.
Now you can use PHP var’s inside the templates to show content given by the shortcode attributes.

1 Like

I think this is now supported in 1.10. You can read more here under the Key-value pair arguments & Interaction conditions sections Dynamic Data – Bricks Academy

1 Like

Since it’s pretty long to type everything here, I made a blog post on this.

https://webcare.co/pass-variable-through-bricks-shortcode/

1 Like