Including reusable logic blocks? Render vs. include tag announcement.

Highlighted
New Member
2 0 2

With this most recent announcement, is there a way to include blocks of Liquid logic and make variable available outside of the snippet, without using the (now depreciated) include tag?

 

For example, I will often abstract variable-setting logic into a snippet that I reuse multiple times in various sections. I expect the variables to be available outside of that snippet. My most recent use case tested for if a section contained "links" - any combination of a 4 fields: 2 text fields, and 2 URL fields. If certain parameters were met, a "has_links" variable was set to true, which was then used conditionally throughout the section, outside of the context of the snippet.

 

With this news, it seems my options are
1) write un-DRY code and explicitly include the (rather verbose) logic every time I need it

2) use the depreciated include tag (while it still works...seems that it is still somewhat supported, but still depreciated)

 

The include tag was very useful for this kind of operation. My impression is that the render tag is intended to actually be responsible for rendering what it contains, but this is not exclusively how snippets have been used in the past. Is there an official workaround, aside from above?

2 Likes