Skip to content

Instantly share code, notes, and snippets.

@TeamDijon
Created June 23, 2024 11:38
Show Gist options
  • Save TeamDijon/15684d1bef3c4bb5ca9dfd8a9381a156 to your computer and use it in GitHub Desktop.
Save TeamDijon/15684d1bef3c4bb5ca9dfd8a9381a156 to your computer and use it in GitHub Desktop.
{% liquid
# The setting is of "richtext" type
assign blog_handle_list = section.settings.blog_handle_list
assign associated_blog_list = ''
assign markup_blog_markup_list = blog_handle_list | split: '</ul>' | first | split: '</li>'
for markup_blog_handle in markup_blog_handle_list
assign blog_handle = static_blog_handle | split: '>' | last
assign associated_blog = blogs[blog_handle]
if associated_blog_list == blank
assign associated_blog_list = associated_blog | uniq
else
assign associated_blog_list = associated_blog | uniq | concat: associated_blog_list
endif
endfor
if associated_blog_list != blank
assign associated_blog_list = associated_blog_list | uniq | reverse
endif
%}
{% for associated_blog in associated_blog_list %}
{% # Access to the blog data in here %}
{% endfor %}
{% comment %}
Example 1: Static content
My setting outputs : <ul><li>first-blog</li><li>second-blog</li><li>third-blog</li></ul>
In the end, I have : [BlogDrop,BlogDrop,BlogDrop]
Example 2: Dynamic content
My setting outputs : <ul class="metafield-single_line_text_field-array"><li class="metafield-single_line_text_field">first-blog</li></ul>
In the end, I have : [BlogDrop]
Example 3: Empty content (static and dynamic)
My settings outputs : ""
In the end, I have : "" (which I can easily test with != blank)
{% endcomment %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment