Ghost Match Helper - How we've utilized match helper to group tags

Picture for the post Ghost Match Helper - How we've utilized match helper to group tags

Hope all the users & readers of Visioun are doing great. We are working on a Ghost Experts project for a client. And the requirement's from the client is to group the tags the same as we group the articles using tags.

First, our approach was to deal with this manually & group the tags in partials by using the from & to option. Something like below

{{#get "tags" limit="all"}}
	{{!-- Group 1 --}}
    {{#foreach tags from="1" to="8"}}
        <a class="" href="{{url}}">{{name}}</a>
    {{/foreach}}
    
    {{!-- Group 2 --}}
    {{#foreach tags from="9" to="16"}}
        <a class="" href="{{url}}">{{name}}</a>
    {{/foreach}}
{{/get}}

Well, the above approach solves the problem for now, but it's very limited. For example, We have created predefined 5 groups for the customer using the above method. Now the client wants to add new tags to groups 2 & 4. It's not possible to do such things without touching the codes.

So we were thinking about how to solve the issue. as we cant add custom fields to the tags data table but we can reuse an existing one. So we went to the API & called a tag. & looking for a field that is not regularly used. & We found two.

  • codeinjection_foot
  • codeinjection_head

So we have decided to use the codeinjection_foot & added a marker for each tag group something like <group1>

So the idea is we will filter out the tags using the custom marker added to Tag Footer into a group.

Here comes the usage of {{#match}} helper. & the example codes are given below.

{{#get "tags" limit="all"}}
	{{!-- Group 1 --}}
    {{#foreach tags}}
        {{#match codeinjection_foot "<group1>"}} {{!-- Get only tags, which codeinjection_foot matches with <group1>  --}}
        	<a class="" href="{{url}}">{{name}}</a>
        {{/match}}
    {{/foreach}}
    
    {{!-- Group 2 --}}
    {{#foreach tags}}
        {{#match codeinjection_foot "<group2>"}} {{!-- Get only tags, which codeinjection_foot matches with <group2>  --}}
        	<a class="" href="{{url}}">{{name}}</a>
        {{/match}}
    {{/foreach}}
{{/get}}

With this approach, the customer can add tags to a particular predefined group without touching the codes. But yes if he needs to add a new group then there is some coding needed.

This is how we solved the issue & the client is very much happy with the approach as his groups are predefined but he will be adding more tags to each group.

Thanks for reading & Hopefully this helps.