Skip to content

Instantly share code, notes, and snippets.

@stvnrynlds
Last active January 19, 2022 14:46
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save stvnrynlds/21461c1d6a4b8124d53428cf2b5e5157 to your computer and use it in GitHub Desktop.
Save stvnrynlds/21461c1d6a4b8124d53428cf2b5e5157 to your computer and use it in GitHub Desktop.
Shopify LinkList API Workaround
{%- layout none -%}
{%- assign listParams = request.path | replace: page.url, "" | remove: "/" | split: '+' -%}
{% if listParams != empty %}
{
{% for param in listParams -%}
{%- assign getList = linklists[param] -%}
{%- if getList != empty %}
"{{ param }}": [{% for level1 in getList.links %}{
"id": "{{ level1.title | handle }}-{{ forloop.index0 }}",
"title": "{{ level1.title }}",
"url": "{% if level1.type != "http_link" %}{{ shop.url }}{% endif %}{{ level1.url }}",
"children": [
{%- for level2 in level1.links -%}
{
"id": "{{ level2.title | handle }}-{{ forloop.index0 }}",
"title": "{{ level2.title }}",
"url": "{% if level2.type != "http_link" %}{{ shop.url }}{% endif %}{{ level2.url }}",
"children": [
{%- for level3 in level2.links -%}
{
"id": "{{ level2.title | handle }}-{{ forloop.index }}",
"title": "{{ level3.title }}",
"url": "{% if level3.type != "http_link" %}{{ shop.url }}{% endif %}{{ level3.url }}"
}
{%- if forloop.last == false %},{% endif -%}
{%- endfor -%}
]
}
{%- if forloop.last == false %},{% endif -%}
{%- endfor -%}
]
}
{%- if forloop.last == false %},{% endif -%}
{% endfor %}
]{%- if forloop.last == false %},{% endif -%}
{% else %}
"{{ param }}": [
{
"status": 404,
"code": "not-found",
"title": "Menu Not Found",
"detail": "Menu `{{ param }}` was not found"
}
]{%- if forloop.last == false %},{% endif -%}
{%- endif -%}
{%- endfor %}
}
{% else %}
{% assign menuHandles = linklists | map: 'handle' %}
["{{ menuHandles | join: '","'}}"]
{% endif %}
@andres9722
Copy link

Thanks!

@arthurcruzd
Copy link

This is awesome!
Thank you very much

@stvnrynlds
Copy link
Author

stvnrynlds commented May 17, 2021

@arthurcruzd Glad it’s helpful! I’m not keeping this up to date with any Shopify Liquid changes so you may need to test it out for yourself. Let me know how you use it!

@phucnvfabbi
Copy link

phucnvfabbi commented Jun 17, 2021

@arthurcruzd Glad it’s helpful! I’m not keeping this up to date with any Shopify Liquid changes so you may need to test it out for yourself. Let me know how you use it!

@stvnrynlds
This is so helpful, thanks!
But I cant accest url of shop look like restAPI, please tell me how. Thanks!!!
https://{user}:{pass}@{mystore}.myshopify.com/pages/menu-api/category-menu -> this is go to page write password of store

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment