Skip to content

Instantly share code, notes, and snippets.

@mitchuman
Last active May 18, 2024 00:21
Show Gist options
  • Select an option

  • Save mitchuman/8cd508eaa2f57b6fb0a3d344732cb2ee to your computer and use it in GitHub Desktop.

Select an option

Save mitchuman/8cd508eaa2f57b6fb0a3d344732cb2ee to your computer and use it in GitHub Desktop.
Liquid utils
{%- liquid
assign announcement_list = section.blocks | where: 'type', 'announcement' | map: 'settings'
for announcement in announcement_list
assign today_date = 'now' | date: '%s' | times: 1
assign start_date = announcement.start_datetime | date: '%s' | times: 1
assign end_date = announcement.end_datetime | date: '%s' | times: 1
if today_date >= start_date and today_date <= end_date
assign data = announcement
elsif announcement.start_datetime == blank and announcement.end_datetime == blank
assign data = announcement
endif
endfor
-%}
{%- if data != blank -%}
{%- if data.url != blank -%}
<a href="{{ data.url }}">
{%- endif -%}
<p>{{ data.content }}</p>
{%- if data.url != blank -%}
</a>
{%- endif -%}
{%- else -%}
<style>
#section-{{ section.id }} {
display: none;
}
</style>
{%- endif -%}
{% schema %}
{
"name": "Announcement bar",
"tag": "aside",
"class": "announcement",
"settings": [],
"blocks": [
{
"type": "announcement",
"name": "Announcement",
"settings": [
{
"type": "header",
"content": "Content"
},
{
"type": "textarea",
"id": "content",
"label": "Content"
},
{
"type": "url",
"id": "url",
"label": "URL"
},
{
"type": "header",
"content": "Scheduling",
"info": "Leave blank to show by default."
},
{
"type": "text",
"id": "start_datetime",
"label": "Start datetime",
"placeholder": "2022-01-01 18:00:00",
"info": "Format: YYYY-MM-DD HH:MM:SS"
},
{
"type": "text",
"id": "end_datetime",
"label": "End datetime",
"placeholder": "2022-01-02 23:59:59",
"info": "Format: YYYY-MM-DD HH:MM:SS"
}
]
}
]
}
{% endschema %}
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"width,height,loading": {
"scope": "html,liquid",
"prefix": "whl",
"body": "width=\"$1\" height=\"$2\" loading=\"${3:lazy}\""
},
"{{ section.settings. }}": {
"scope": "liquid,html",
"prefix": "ss",
"body": "{{ ${2:section.settings}.${1:content} }}"
},
"{% tag %}": {
"scope": "liquid,html",
"prefix": "tag",
"body": "{% $1 %}"
},
"schema: heading + description": {
"scope": "liquid,html",
"prefix": "schema: heading + description",
"body": [
"{",
"\t\"type\": \"text\",",
"\t\"id\": \"heading\",",
"\t\"label\": \"Heading\"",
"},",
"{",
"\t\"type\": \"textarea\",",
"\t\"id\": \"description\",",
"\t\"label\": \"Description\"",
"}"
]
},
"schema: CTA": {
"scope": "liquid,html",
"prefix": "schema: CTA",
"body": [
"{",
"\t\"type\": \"text\",",
"\t\"id\": \"cta_label\",",
"\t\"label\": \"CTA label\"",
"},",
"{",
"\t\"type\": \"url\",",
"\t\"id\": \"cta_link\",",
"\t\"label\": \"CTA link\"",
"}"
]
},
"markup: CTA": {
"scope": "liquid,html",
"prefix": "markup: CTA",
"body": [
"{%- if section.settings.cta_link != blank -%}",
"\t<p>",
"\t\t<a href=\"{{ section.settings.cta_link }}\">",
"\t\t\t{{ section.settings.cta_label }}",
"\t\t</a>",
"\t</p>",
"{%- endif -%}",
]
},
"image_tag": {
"scope": "liquid,html",
"prefix": "image_tag",
"body": [
"{{ ${1:section.settings.image}",
"\t| image_url: width: ${2:800}",
"\t| image_tag: ${3:loading: 'lazy'}",
"}}",
]
},
"blocks": {
"scope": "liquid,html",
"prefix": "blocks",
"body": "{%- assign ${1:item}s = section.blocks | where: 'type', '${1:items}' | map: 'settings' -%}"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment