Skip to content

Instantly share code, notes, and snippets.

@arthurcruzd
Forked from stvnrynlds/menus-api.liquid
Created May 17, 2021 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurcruzd/71826a217d6b194e866d8d8c4f88ce2f to your computer and use it in GitHub Desktop.
Save arthurcruzd/71826a217d6b194e866d8d8c4f88ce2f 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 %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment