Rendering snippets conditionally based on product tags in Dawn 2.0 theme

I am trying to render snippets based on product tags…the snippet to be rendered has the same name as the tag. For example, a product has the tag automatic-custom-name, and the snippet that I want rendered is called automatic-custom-name. I’ve used the following code on my 1.0 theme for years and it works perfectly, pulling in each snippet based on whatever tags the product has, but I cannot get a similar setup to work in my Dawn 2.0 theme.

{% if tag contains ‘automatic-’ %}
{% assign tagname = tag %}

{% render ‘tag’ %}
{% endif %}

So what I need is a way to tell it to render the snippet that has the same name as the tag, if the tag starts with automatic-

Any ideas? Thanks in advance!

Hey @Laurie_ONeill ,

Is ‘tag’ a variable? As far as I know it’s ‘product.tag’, unless tag = product.tag

{% if tag contains 'automatic-' %}

I’m trying to make it variable, so if there is a tag with a name that starts with automatic-, it will pull in the snippet with the same name that the tag has. So for example if there’s a tag called automatic-custom-name, it will pull in a snippet that is called automatic-custom-name. And do that for any other tags that start with automatic. If the tag is called automatic-custom-age, it would pull in the snippet called automatic-custom-age etc. I know I can do it with individual if statements for each tag, but would love to find a simple variable solution instead of having to put in hundreds of individual lines of code.

I sell personalized items with hundreds of possible options and have a complicated system that all works based on those few lines of code that someone else wrote those few lines of code for me years ago, and am trying to figure out how to get that same system to work in 2.0!