Shopify Drop-Down Menu : Show collection product count - drop-down-menu

i am working on a Shopify Store here and need to display the product count for each collection in the drop-down sub-menu and somehow I can not figure it out. The documentation is a little bit light on this issue.
I need the product count to be shown only in the sub-menus.
I tried adding the code below but it snot working:
{% if childlink.type == 'collection_link' %}
({{ childlink.object.products_count }})
{%endif%}
Can anyone help me out with this? Below is my code:
<div class="dropdown-menu">
<div class="row tt-col-list">
<div class="col">
<ul class="tt-megamenu-submenu tt-megamenu-preview">
{%- for child_level_2 in level_2.links -%}
<li><span>{{ child_level_2.title }} </span>
{%- capture return -%}{%- include "get_linklist_dropdown", link: child_level_2 -%}{%- endcapture -%}{%- assign return = return | split: "%%" -%}{%- assign has_drop_down = return | first | strip -%}{%- assign child_list_handle = return | last | strip -%}
{%- assign level_3 = linklists[child_list_handle] -%}
{%- if level_3.empty? -%}
{%- assign child_list_handle = child_level_2.title | handle -%}
{%- assign level_3 = linklists[child_list_handle] -%}
{%- endif -%}
{%- if level_3.links != blank -%}
<ul>
{%- for child_level_3 in level_3.links -%}
<li>
<span>{{ child_level_3.title }}</span>
{%- capture return -%}{%- include "get_linklist_dropdown", link: child_level_3 -%}{%- endcapture -%}{%- assign return = return | split: "%%" -%}{%- assign has_drop_down = return | first | strip -%}{%- assign child_list_handle = return | last | strip -%}
{%- assign level_4 = linklists[child_list_handle] -%}
{%- if level_4.empty? -%}
{%- assign child_list_handle = child_level_3.title | handle -%}
{%- assign level_4 = linklists[child_list_handle] -%}
{%- endif -%}
{%- if level_4.links != blank -%}
<ul>
{%- for child_level_4 in level_4.links -%}
<li>
<span>{{ child_level_4.title }}</span>
{%- capture return -%}{%- include "get_linklist_dropdown", link: child_level_4 -%}{%- endcapture -%}{%- assign return = return | split: "%%" -%}{%- assign has_drop_down = return | first | strip -%}{%- assign child_list_handle = return | last | strip -%}
{%- if has_drop_down == "true" -%}
{%- assign level_5 = linklists[child_list_handle] -%}
{%- unless level_5.empty? -%}
<ul>
{%- for child_level_5 in level_5.links -%}
<li>{{ child_level_5.title }}</li>
{%- endfor -%}
</ul>
{%- endunless -%}
{%- endif -%}
</li>
{%- endfor -%}
</ul>
{%- endif -%}
</li>
{%- endfor -%}
</ul>
{%- endif -%}
</li>
{%- endfor -%}
</ul>
</div>
</div>
</div>
</pre>

Related

nunjucks equivalent to liquid capture in this loop?

Current liquid capture loop
{% if page.related %}
{% capture results %}
[ {% for category in page.categories %}
{% for post in site.categories[category] %}
{% if post.url != page.url %}"{{ post.url | relative_url | prepend: site.url }}"{% unless forloop.last %},{% endunless %}{% endif %}{% if forloop.last %}],{% endif %}{% endfor %}{% endfor %}
{% endcapture %}
"relatedLink":{{ results }}
{% else %}{% endif %}
I read about nunjucks set filter. I'm just not sure what would be the equivalent?

Is there a way to override the schema names for dbt Cloud CI runs?

We use dbt cloud to run our dbt project. On CI runs, dbt Cloud uses a schema name related to the PR number, e.g. dbt_cloud_pr_5205_543.
Is there a way to override this behavior?
Update: we've updated our macro as below.
generate_schema_name.sql
% macro generate_schema_name(custom_schema_name, node) -%}
{%- set default_schema = target.schema -%}
{%- if target.name[-3:] == 'dev' -%}
{{ target.schema }}_{{ custom_schema_name | trim }}
{%- elif target.schema[:9] == 'dbt_cloud' -%}
{{ target.schema }}_{{ custom_schema_name | trim }}
{%- elif custom_schema_name is none -%}
{{ default_schema }}
{%- else -%}
{{ custom_schema_name | trim }}
{%- endif -%}
{%- endmacro %}
This macro resolved the problem:
generate_schema_name.sql
{% macro generate_schema_name(custom_schema_name, node) -%}
{%- set default_schema = target.schema -%}
{%- if target.name[-3:] == 'dev' -%}
{{ target.schema }}_{{ custom_schema_name | trim }}
{%- elif target.schema[:9] == 'dbt_cloud' -%}
{{ target.schema }}_{{ custom_schema_name | trim }}
{%- elif custom_schema_name is none -%}
{{ default_schema }}
{%- else -%}
{{ custom_schema_name | trim }}
{%- endif -%}
{%- endmacro %}

Ansible jinjia2 template whitespaces control

Question
How do I get the desired output?
Code
yaml
nodeStatusUpdateFrequency:
{% if nodeStatusUpdateFrequency is defined -%}
{{ nodeStatusUpdateFrequency }}
{% else -%}
{%- if nodeStatusUpdate == 'Fast' -%}
4s
{%- elif nodeStatusUpdate == 'Medium' -%}
20s
{%- elif nodeStatusUpdate == 'Low' -%}
1m
{% else -%}
10s
{% endif %}
{%- endif %}
oomScoreAdj: -999
Output:
My current output is:
nodeStatusUpdateFrequency: $x
oomScoreAdj: -999
Desired Output:
My expected output is:
nodeStatusUpdateFrequency: $xoomScoreAdj: -999
Your template is OK. The play below with copy&paste of your template
vars:
nodeStatusUpdateFrequency: "$x"
nodeStatusUpdate: "NONE"
tasks:
- template:
src: test-template.j2
dest: /scratch/test.txt
gives:
# cat /scratch/test.txt
nodeStatusUpdateFrequency: $x
oomScoreAdj: -999
You are simply missing the minus (-) signs on some of your endif control structures. This is doing the job as you expect:
nodeStatusUpdateFrequency:
{%- if nodeStatusUpdateFrequency is defined -%}
{{ nodeStatusUpdateFrequency }}
{%- else -%}
{%- if nodeStatusUpdate == 'Fast' -%}
4s
{%- elif nodeStatusUpdate == 'Medium' -%}
20s
{%- elif nodeStatusUpdate == 'Low' -%}
1m
{%- else -%}
10s
{%- endif -%}
{%- endif -%}
oomScoreAdj: -999

variant & price load in shopify

Product price for default variant is working.When i change variant "Inc VAT" is not changing automatically.
I want to change product price automatically, when i will change variant of a product. See the store-
https://woodies-timber.myshopify.com/products/bendi-ply-long-grain
<div class="price dvt-vat">
{%- include 'limited-offer' -%}
<div id="price">
{%- if product.available -%}
<span class="price-new money">{{current_variant.price | money}}</span>
{%- if current_variant.compare_at_price > current_variant.price -%}
<span class="price-old money">{{current_variant.compare_at_price | money}}</span>
{%- endif -%}
{%- else -%}
<span class="price-old">{{'products.product.sold_out' | t}}</span>
{%- endif -%}
</div>
<span class="exl-vat">Exl VAT</span>
{% assign dvt_price = current_variant.price %}
{% assign dvt_price_prat = current_variant.price | times :20 | divided_by :100 | plus: current_variant.price | money %}
<br>
<span class="price-new money dvt_price_totlal">{{ dvt_price_prat }}</span>
<span class="exl-vat">Inc VAT</span>
</div>

FInd last matched element using Liquid

I'm working on custom solution for Shopify store and my problem is that I can't manage how to avoid adding ' / ' after the last matched tag in the case statement.
I've tried to use some if statements with a forloop filters with no result.
The last thing on my mind was finding the last matched tag in the loop that will help us avoiding ' / ' after the last element, but unfortunately I can't manage how to do that.
Expected result: Wool/Nylon/Viscose
Here is the part of the code that compares all tags assigned to the product with the list of tags(clothing materials) required for the output.
Considering that product has such tags as Wool, Nylon and Viscose and others, non material.
Example 1
Actual & Expected Result: WoolNylonViscose
{% for tag in product.tags %}
{% case tag %}
{% when 'Viscose' %}
Viscose
{% when 'Wool' %}
Wool
{% when 'Polyamide' %}
Polyamide
{% when 'Nylon' %}
Nylon
{% else %}
{% endcase %}
{% endfor %}
Example 2
Filter forloop.last was used to define the last element of the loop, but the problem is that material tags(Wool, Nylon, Viscose) can be in the middle of the product tag array. Considering product has 10 tags and material tags are spread among the array we will see next result.
Result: ///Wool/Nylon////Viscose//
{% for tag in product.tags %}
{% if forloop.last == true %}
{% case tag %}
{% when 'Viscose' %}
Viscose
{% when 'Wool' %}
Wool
{% when 'Nylon' %}
Nylon
{% else %}
{% endcase %}
{% else %}
{% case tag %}
{% when 'Viscose' %}
Viscose
{% when 'Wool' %}
Wool
{% when 'Nylon' %}
Nylon
{% else %}
{% endcase %}
/
{% endif %}
{% endfor %}
I would appreciate if you could please point on my mistakes and suggest me how can i achieve solution.
This should work:
{% capture tag_string %}{% endcapture %}
{% for tag in product.tags %}
{% if tag == 'Viscose' %}{% capture tag_string %}{{ tag_string }}Viscose/{% endcapture %}
{% elsif tag == 'Wool' %}{% capture tag_string %}{{ tag_string }}Wool/{% endcapture %}
{% elsif tag == 'Polyamide' %}{% capture tag_string %}{{ tag_string }}Polyamide/{% endcapture %}
{% elsif tag == 'Nylon' %}{% capture tag_string %}{{ tag_string }}Nylon/{% endcapture %}
{% endif %}
{% endfor %}
{{ tag_string | split: "" | reverse | join: "" | remove_first: "/" | split: "" | reverse }}
More on string filters: https://help.shopify.com/themes/liquid/filters/string-filters
You can try the following:-
{% for tag in product.tags %}
{% case tag %}
{% when 'Viscose' %}
{{ 'Viscose' | append: '/' }}
{% when 'Wool' %}
{{ 'Wool' | append: '/' }}
{% when 'Polyamide' %}
{{ 'Polyamide' | append: '/' }}
{% when 'Nylon' %}
{{ 'Nylon' }}
{% else %}
{% endcase %}
{% endfor %}

Resources