Hi guys,
I need certain conditional rules in Liquid based on whether the theme is the published one or not. In short, I need some logic to detect when the theme is NOT the production one. I was getting this information from the theme object, but now I realize it is deprecated. Any idea how I can achieve that?
I think you can probably use something like {{ request.query.preview_theme_id }}
since all preview (unpublished) themes will have a preview_theme_id
query param in their respective storefront URL.
{% if request.query.preview_theme_id %}
Do something here
{% endif %}
Others chime in, I may be off-base here.
EDIT: this isn’t a thing unfortunately… – wishful thinking on my part.
This isn’t valid unfortunately.
Brain fart, figured that was too easy lol. I think I’m blending js and liquid together. Only other way I know off the top is Shopify.theme.role
in the window, you could probably capture that, but you’d have to use JS which is not ideal… you would think there would be an easy way to do this server-side.
I think you can try with manual way. Use metafield or try with schema setting.
Hi @Inflameweb_dev
I am wondering how schema settings could be helpful in this case?
Hi @Luke . do you have any other idea?
Hi @Inflameweb_dev
I am wondering how schema settings could be helpful in this case?
It’s not great, but I guess he means that you could have a theme setting setting.is_production
thats enabled on the production theme only
Hi @curzey ! hmm i am still trying to undertand how this settings would work. Can you provide a simple example? thanks
settings_schema.liquid
{
"type": "checkbox",
"id": "is_production",
"label": "Is production",
"default": false
}
Set that setting to true
(via the customizer, manually) on your production theme.
{% if settings.is_production %}
{% comment %}
Render your conditional liquid only for live theme (or reverse for offlines)
{% endcomment %}
{% endif %}
Obviously really depends what the real case is for you to need this setting. Not aware of other solutions anyway.