Skip to main content

Reusing Markup with Shared

Whether it is Liquid logic or using a template to render content, the Shared tab of the plugin builder is used by all markup views.

Mario avatar
Written by Mario
Updated today

The Shared tab in the plugin builder does exactly what it says on the tin; any code inside is processed before any View, allowing you to keep logic and templates in one place, and keep layouts focused on the look of things.

DRY Code

DRY (Don't Repeat Yourself) helps keep things organized and reduce the chance of copy/paste mistakes when developing or improving your plugins.

It's a best-practice to put Liquid logic in Shared if it's preprocessing Your Variables. If you put "A" in Shared and then "B" in your Full view, then plugin would display "AB". This is equivalent to copy/pasting all the Share content into each view (exhausting!).

Templates

Shared doesn't have to only include logic, it can also include a Template, which you can pass key:value pairs to render content dynamically, while still limiting duplication.

For more info, check out our plugin docs.

TIP: When using a template, Your Variables are not automatically included, you have to pass them in. This is most commonly a "gotcha" when you need the trmnl variable's data, your render could look like:

{% render "my_template", trmnl: trmnl %}

Don't leave views empty

Our renderer will skip a view that does not contain any markup, so your plugin will display "Full view not available" in this case. If you are using all of your code from Shared, just add some commented code to the empty editor box to avoid seeing errors:

Did this answer your question?