Skip to main content

Liquid Templating Puzzle

 

Hi, I'm a Nationbuilder Architect working on a site for Living Room Conversations.

I've run into a liquid templating problem that I can't seem to solve.  I have a convoluted solution that I don't know why it's not working, but I'm also looking for a better way.

livingroomconversations.nationbuilder.com/topics. This is the page I'm working on.

I am trying to list our topics in alphabetical order and remove duplicate titles/headlines.  Topics are children of Categories which are children of The Topics Page.

Here is the code I am trying... It is failing to 1) remove duplicates 2) remove empty items

<ul id='full-topics-list' class='cf'>
{% capture topics %}
{% for category in page.children %}
{% for topic in category.children| sort:"value" %}
{% if topic.headline != blank %}
{% unless topic_headlines contains topic_headline %}
|{{ topic.headline }}#{{ topic.url }}
{% endunless %}
{% endif %}

<!-- constructing array for deduplication -->
{% capture topic_headlines %}
{{topic_headlines | join: '|'}}|{{topic.headline}}
{%endcapture%}
{% capture topic_headlines %}
{{topic_headlines | split: '|'}}
{%endcapture%}

{% endfor %}
{% endfor %}
{% endcapture %}

{% assign sortedtopics = topics | split: '|' | sort %}
{% for topic in sortedtopics %}
{% assign topicitems = topic | split: '#' %}
<li class='cf'> <a href="{{ topicitems[1] }}">{{ topicitems[0] }}</a></li>
{% endfor %}



</ul>

 

Official response from

Hey Peter - It looks like you've figured this out, as that page seems to show all of the topics in alphabetical order with no duplicates. If you have further questions, let us know! In addition, if you have any tips/tricks for folks seeking to do the same thing, feel free to post them here as a comment!

Share this post

Showing 3 reactions

How would you tag this suggestion?
Please check your e-mail for a link to activate your account.