Assign multiple variables for shop domain

mgenest
Shopify Partner
13 0 7

Hi,

 

I'm trying to assign two global variables in my theme.liquid file for shop.domain:

 

{% assign shop_domain_bouquets =
shop.domain == 'bouquets-belle-fleur-dev.myshopify.com' or shop.domain == 'bouquets.bellefleurny.com' or shop.domain == 'bouquets-belle-fleur-ny.myshopify.com' %}

{% assign shop_domain_fragrance =
shop.domain == 'belle-fleur-dev02.myshopify.com' or shop.domain == 'belle-fleur-ny.myshopify.com' or shop.domain == 'bellefleurny.com' or shop.domain == 'www.bellefleurny.com' %}

I'm not sure if I need to escape the quotes, but it seems to work no problem for the first variable when I call it like so:

 

{% if shop_domain_bouquets %} active {% endif %} <--WORKS
{% if shop_domain_fragrance %} active {% endif %} <--DOES NOT WORK

But it consistently won't work for the second variable. I'm not sure why. Can anybody tell me what I'm doing wrong or if I have the syntax incorrect?

 

Thanks!

0 Likes
ArcticKeys
Tourist
8 1 1

Hi mgenest,

 

Based on the code you provided, you won't be able to assign both global variables with the given statement because 'shop.domain' can only be set equal to values in one logic statement and not the other since there are no intersection in the conditions.

 

So only 1 group will be active and not the other, or vice versa.

 

I'm currently seeing this as (If I pretended that each of your string is a unique number):

 

assign shop_domain_bonquets = shop.domain if shop.domain is equal to 1, 2, 3

assign shop_domain_fragrance = shop.domain if shop.domain is equal to 4, 5, 6, 7

 

There is no intersection in both conditions for shop.domain, therefore you can't have both items active at the same time.

 

So the question is back to the logic. What do you want to assign each global variable and under what circumstances?

 

I hope this was helpful

0 Likes
mgenest
Shopify Partner
13 0 7

Sorry, it wasn't clear. This was only for example purposes, but it is a theme that is customized to operate on two shops, so only one var will be true at any one time. I need to call both variables to run conditionals on them and add remove content accordingly. So essentially I want to replace the domain calls with one snippet (or something similar) containing the two variables to simplify the code and be able to add/remove domains centrally without having to update multiple templates. Hope that makes sense. Thanks!

0 Likes
mgenest
Shopify Partner
13 0 7

Thanks for the response. Essentially I want two global vars that i can substitute for this:

 

{% if shop.domain == 'bouquets-belle-fleur-dev.myshopify.com' or shop.domain == 'bouquets.bellefleurny.com' or shop.domain == 'bouquets-belle-fleur-ny.myshopify.com' %}{% endif %}
{% if shop.domain == 'belle-fleur-dev02.myshopify.com' or shop.domain == 'belle-fleur-ny.myshopify.com' or shop.domain == 'bellefleurny.com' or shop.domain == 'www.bellefleurny.com' %}{% endif %}

That way i can manage from a snippet and modify as needed without having to adjust every instance in the templates.

 

Based on your answer, I'm still having the same problem. If I use your syntax and write the var:

 

{% assign shop_domain_bouquet = shop.domain if shop.domain is equal to 'bouquets-belle-fleur-dev.myshopify.com', 'bouquets.bellefleurny.com', 'bouquets-belle-fleur-ny.myshopify.com' %}
{% assign shop_domain_fragrance = shop.domain if shop.domain is equal to 'belle-fleur-dev02.myshopify.com', 'belle-fleur-ny.myshopify.com', 'bellefleurny.com', 'www.bellefleurny.com' %}

The shop_domain_bouquet will work while the shop_domain_fragrance will not.

 

I need to call both of them in the template in different instances, depending on what content is being shown. 

 

For example, if I want a different page link on the bouquet shop vs the fragrance shop, I write:

 

{% if shop.domain == 'bouquets-belle-fleur-dev.myshopify.com' or shop.domain == 'bouquets.bellefleurny.com' or shop.domain == 'bouquets-belle-fleur-ny.myshopify.com' %}
href='/pages/floral-bouquets'
{% else %}
href='/pages/floral-weddings-blanc-et-noir'
{% endif %}

 

If I'm on the bouquets shop, the condition will be true and it will show the correct link.

However, I may also want the condition to be false on the bouquets shop and will call something like this:

 

{% if shop.domain == 'belle-fleur-dev02.myshopify.com' or shop.domain == 'belle-fleur-ny.myshopify.com' or shop.domain == 'bellefleurny.com' or shop.domain == 'www.bellefleurny.com' %}
  href='/fragrance'
{% else %}
  href='https://www.bellefleurny.com/fragrance'
{% endif %}

This in which case the condition will be false and will still show the correct link.

 

However, if I try to call the variable shop_domain_fragrance (which essentially should do the same thing) it will not work.

Any ideas why?

0 Likes
mgenest
Shopify Partner
13 0 7

Thanks for the response. Essentially I want two global vars that i can substitute for this:

 

{% if shop.domain == 'bouquets-belle-fleur-dev.myshopify.com' or shop.domain == 'bouquets.bellefleurny.com' or shop.domain == 'bouquets-belle-fleur-ny.myshopify.com' %}{% endif %}
{% if shop.domain == 'belle-fleur-dev02.myshopify.com' or shop.domain == 'belle-fleur-ny.myshopify.com' or shop.domain == 'bellefleurny.com' or shop.domain == 'www.bellefleurny.com' %}{% endif %}

That way i can manage from a snippet and modify as needed without having to adjust every instance in the templates.

 

Based on your answer, I'm still having the same problem. If I use your syntax and write the var:

 

{% assign shop_domain_bouquet = shop.domain if shop.domain is equal to 'bouquets-belle-fleur-dev.myshopify.com', 'bouquets.bellefleurny.com', 'bouquets-belle-fleur-ny.myshopify.com' %}
{% assign shop_domain_fragrance = shop.domain if shop.domain is equal to 'belle-fleur-dev02.myshopify.com', 'belle-fleur-ny.myshopify.com', 'bellefleurny.com', 'www.bellefleurny.com' %}

The shop_domain_bouquet will work while the shop_domain_fragrance will not. I need to call both of them in the template in different instances, depending on what content is being shown. For example, if I want a different page link on the bouquet shop vs the fragrance shop, I write:

 

{% if shop.domain == 'bouquets-belle-fleur-dev.myshopify.com' or shop.domain == 'bouquets.bellefleurny.com' or shop.domain == 'bouquets-belle-fleur-ny.myshopify.com' %}
href='/pages/floral-bouquets'
{% else %}
href='/pages/floral-weddings-blanc-et-noir'
{% endif %}

If I'm on the bouquets shop, the condition will be true and it will show the correct link.

However, I may also want the condition to be false on the bouquets shop and will call something like this:

 

{% if shop.domain == 'belle-fleur-dev02.myshopify.com' or shop.domain == 'belle-fleur-ny.myshopify.com' or shop.domain == 'bellefleurny.com' or shop.domain == 'www.bellefleurny.com' %}
  href='/fragrance'
{% else %}
  href='https://www.bellefleurny.com/fragrance'
{% endif %}

This in which case the condition will be false and will still show the correct link.

 

However, if I try to call the variable shop_domain_fragrance (which essentially should do the same thing) it will not work.

Any ideas why?

0 Likes
mgenest
Shopify Partner
13 0 7

I'm sorry but it still is the same problem. The fragrance variable will never work, under any circumstance.

I'm just trying to create two variables that replace this:

 

{% if shop.domain == 'bouquets-belle-fleur-dev.myshopify.com' or shop.domain == 'bouquets.bellefleurny.com' or shop.domain == 'bouquets-belle-fleur-ny.myshopify.com' %}{% endif %}
{% if shop.domain == 'belle-fleur-dev02.myshopify.com' or shop.domain == 'belle-fleur-ny.myshopify.com' or shop.domain == 'bellefleurny.com' or shop.domain == 'www.bellefleurny.com' %}{% endif %}

So I can call them from a snippet and easily modify. Any ideas? Thanks!

0 Likes
ArcticKeys
Tourist
8 1 1

I'm a little confused about your previous responses. I'm assuming you are trying to use the same code but for 2 different lists of web domains.

 

Using only Liquid, I don't know how you can create Global variables to manipulate in snippet.

 

My thoughts are, if you do check different web domains, have the if statements on the outside and each link to the general webpage inside.

 

So when you go to the website: 'bouquets-belle-fleur-dev.myshopify.com' it will redirect to the first webpage.

 

If you go to the domain 'belle-fleur-dev02.myshopify.com, you will go to the second webpage.

{% if shop.domain == 'bouquets-belle-fleur-dev.myshopify.com' or shop.domain == 'bouquets.bellefleurny.com' or shop.domain == 'bouquets-belle-fleur-ny.myshopify.com' %}
redirect to general webpage 1
{%
endif %} {% if shop.domain == 'belle-fleur-dev02.myshopify.com' or shop.domain == 'belle-fleur-ny.myshopify.com' or shop.domain == 'bellefleurny.com' or shop.domain == 'www.bellefleurny.com' %}
redirect to general webpage 2
{%
endif %}

Your general webpage will have the bulk of the code that you modify individually without affecting the other webpage.

 

If this resolves your issue, I recommend just creating 2 separate websites with their individual base codes rather than splitting it in the same area.

0 Likes
mgenest
Shopify Partner
13 0 7
Thanks for your response. I’ve already got the code working on two different stores using one theme with the long form versions (shop.domain == ‘ ‘ or shop.domain == ‘ ‘ ...) and it works fine if it evaluates to true or false. I can include content if the shop domain equals the shop I’m on and even exclude content if the shop domain does not equal the shop I’m on (if that makes sense).

I’m just trying to create a variable that will replace these long calls between the if/else statements with a single identifier for each to make the code less cumbersome and easier to maintain. Then I can add a snippet referencing the variables in the main theme.liquid file and update from a single file.

What I am having problems with is having both variables work properly. If I’m simply switching out the long calls with a single variable it should work (like replacing a long string with escaped quotes for a single variable in JavaScript). No matter what I try though I can’t get it to work for both. I’ve tried to capture the value and plug it in as well, no luck. So assign and capture only seem to recognize the variable that matches true to the domain I’m on, which is weird because I can also exclude content that evaluates to false in the long form versions. So I’m confused as to why. There must be a way to assign each to a single variable and have them work exactly like they do now.

Thanks for trying anyway. Maybe it’s not meant to be.
0 Likes