About
Globo is the company specializing in website design and development in Vietnam.
18 Khuc Thua Du Street, HN
globosoftware
[email protected]
Follow Us

How to create the customized template

You are here:
Estimated reading time: 1 min
How to create the customized search template
  1. Go to the Edit Code page
  2. Click Add a new template
  3. Select Search
  4. Select liquid
  5. Enter the file name “globo.alsobought” → Click Done
  6. Paste the code script below in the file search.globo.alsobought.liquid template you just created
{%- layout none -%}
{%- if search.terms == 'data' -%}
{%- assign tags = '' -%}
{"collections":[
{%- for collection in collections -%}
{"id":"{{-collection.id-}}","handle":"{{-collection.handle-}}","title":{{collection.title | json}},"image":{%- if collection.image -%}{{- collection.image | img_url: '100x' | json -}}{%- else -%}null{%- endif -%}}{%- unless forloop.last -%},{%- endunless -%}
{%- endfor -%}
],"vendors":{{shop.vendors | json}},"types":{{shop.types | json}},"tags":{{ collections.all.all_tags | json }}}
{%- elsif search.terms contains 'handles:' -%}
[
{%- assign params = canonical_url | url_decode | split: "?" | last | split: "&" -%}
{%- assign handles = '' -%}
{%- for str in params -%}
{%- assign str_split = str | split: "=" -%}
{%- if str_split.first == 'q' -%}{%- assign handles = str_split.last | remove_first: "handles:" -%}{%- endif -%}
{%- endfor -%}
{%- if handles != '' -%}
{%- assign handles = handles | split: "|" -%}
{%- for handle in handles limit:20 -%}
{% assign product = all_products[handle] -%}{%- unless forloop.first -%},{%- endunless -%}{{-product | json-}}
{%- endfor -%}
{%- endif -%}
]
{%- else -%}
{%- if search.results_count > 0 -%}{%- assign comma = '' -%}
{%- paginate search.results by 12 -%}[{%- for product in search.results -%}{{comma}}{%- assign comma = ',' -%}
{
"id":{{- product.id -}},
"available": {{- product.available -}},
"title":{{- product.title |json -}},
"handle":{{- product.handle |json -}},
"images":{{- product.images | json -}},
"tags":{{- product.tags |json -}},
"collections": {{- product.collections | json -}},
"type":{{- product.type |json -}},
"variants":{{- product.variants |json -}},
"vendor":{{- product.vendor |json -}},
"price":{{- product.price |json -}},
"compare_at_price":{{- product.compare_at_price |json -}}
}
{%- endfor -%}]{%- endpaginate -%}{%- else -%}[]
{%- endif -%}
{%- endif -%}

7.Click Save to finish

How to create the customized collection template
  1. Go to the Edit Code page
  2. Click Add a new template
  3. Select Collection
  4. Select liquid
  5. Enter the file name “globo.alsobought → Click Done
  6. Paste the code script below in the file collection.globo.alsobought.liquid template you just created
{%- layout none -%}
{%- if collection.all_products_count > 0 -%}
{%- assign limit = 25 -%}{%- assign count = 0 -%}
{%- paginate collection.products by 25 -%}
[{%- for product in collection.products -%}
{%- unless count == 0 -%},{%- endunless -%}
{{-product | json-}}
{%- assign count = count | plus: 1 -%}
{%- if count >= 25 -%}{%- break -%}{%- endif -%}
{%- endfor -%}]
{%- endpaginate -%}
{%- else -%}[]{%- endif -%}

7.Click Save to finish

If you encounter any difficulties or have any questions, please don’t hesitate to contact us at [email protected]

Was this article helpful?
Dislike 3566
Views: 1486