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?

5 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

Interesting but too complicated.

@timmse It is possible in current BB version?

It’s not supported @jaclas .
The official request on the idea board has 28 upvotes so far:

However, since 1.12, most scenarios (text, query loop) can be achieved with components:

@timmse

I build the site in Bricks, but the content is created as classic Wordpress posts using the Gutenberg editor.
Is it possible to create a component that can be used by an operator who creates an post from within the Gutenberg editor? That is, in some cases, in some posts, the operator needs to embed a component with some text (any text, depending on the operator’s need) and this will be displayed in the Bricks component? Is this possible using components?
Because the template can embed using shortcode, but just lacks the ability to simply pass the text (content).

You could add a custom field that you then output within the template (whether in a component or not).