CMS Development

WEDIA
メンバー | Gold Partner
メンバー | Gold Partner

Content Tags printed the wrong order

Hello all,

I have a problem when creating and article. I fill the TAGS with certain order but when I'm looping through them with the code below i get wrong order.

 {% if content.tag_list %}
<div id="hubspot-topic_data" class="primary-tags text-center">
{% for tag in content.tag_list %}
{% if loop.index == 1 %}
<a class="topic-link" href="{{ blog_tag_url(group.id, tag.slug, 1) }}">{{ tag.name }}</a>
{% endif %}
{% endfor %}
{% endif %} 

The order i have filled the tags inside my article is TAG1, TAG2, TAG3.

 

The code above prints TAG3 as my first tag.

 

Any ideas why this happenning? Sorting doesn't help because i dont' want my tags to print sorted by name. I want the specifically TAG1 to be printed always.

0 いいね!
6件の返信
Jsum
キーアドバイザー

Content Tags printed the wrong order

@edjusten@TRooInbound@WEDIA,

 

This comes down to how the topics are stored in Hubspot. Hubspot is built in python like WordPress is built in PHP. Python has a few storage types such as lists, tuples, and dictionaries or dicts. While technically the topics could be stored as a tuple, it makes the most sense for them to be stored as a dictionary. 

 

The unfortunate downside to dicts is that they are unordered by default. By this I mean that chronology alphabetical order are not recognized. it doesn't matter when or in what order you enter topics into the list, they will be output as seen fit by the system.

 

There is a dictsort filter in the HubL docs filter reference. I havent used it but you seam to be able to sort dicts by key or value. I'm not sure of the sorting criteria but I would imagine it is alphabetical.

 

 

Another thing I have noticed, but is unconfirmed, about topics is that you never actual access a post specific list of posts. Instead, what I am finding, is that any reference to topics is pointed to the list of topics for a blog as a whole, and the topics tied to each post is ouput from that list. If this is the case then it would make things even more difficult. 

 

As far as suggestions go, there's not really much I can offer in the way of a solution. You could fake the topics using a text module export to the template, you could create a  list from the dict of topics, though that would require some python knowledge but I have confirmed you can do this, or you could use javascript to superficially sort the topics based on a sorting algorithm that you would have to come up with (x always comes before y, y always comes before z, etc.).0

josephLayden
投稿者

Content Tags printed the wrong order

Can you confirm your previous hypotheses?  I am trying to access the post specific tags.

 

"Another thing I have noticed, but is unconfirmed, about topics is that you never actual access a post specific list of posts. Instead, what I am finding, is that any reference to topics is pointed to the list of topics for a blog as a whole, and the topics tied to each post is ouput from that list. If this is the case then it would make things even more difficult."

0 いいね!
edjusten
HubSpot Employee
HubSpot Employee

Content Tags printed the wrong order

Thanks @Jsum for your knowledge and willingness to share! スマイリー ハッピー

 

Ed 


Did my post help answer your query? Help the Community by marking it as a solution
0 いいね!
WEDIA
メンバー | Gold Partner
メンバー | Gold Partner

Content Tags printed the wrong order

Hello all,

 

Thanks for your answers.

 

I managed to find the solution which i think must be included at the docs.

 

{% for topic_id in content.tag_ids %}
{% for topic in content.topic_list %}
{% if topic_id == topic.id %}
<a class="topic-link" href="{{ blog_tag_url(group.id, topic.slug) }}">{{ topic.name }}</a>
{% endif %}
{% endfor %}
{% endfor %}
TRooInbound
キーアドバイザー

Content Tags printed the wrong order

Hi @WEDIA

 

We go through your issue and while investigate we found that the tags set in post might come in a random manner using HubL code.

 

@edjusten Can you please help us on this.

0 いいね!
edjusten
HubSpot Employee
HubSpot Employee

Content Tags printed the wrong order

Apologies, not my area of expertise. Perhaps @Jsum can jump in here?

 

Ed 


Did my post help answer your query? Help the Community by marking it as a solution
0 いいね!