Accessing tag attributes in theme when using Content Hub routes


#1

I created a content hub called properties by following this tutorial:

Now when I tag a post as properties it shows up in my /properties/ url just as I want.

I made a custom template and I would like to access the attributes of the properties tag but I cannot find instructions on how to do that.


#2

So this is what I came up with, is there a better way?

{{#get "tags" filter="slug:properties"}}

    {{#foreach tags}}
<div class='c-tag-hero' style='background-image: url({{ img_url feature_image }})'>
    <div class='c-tag-hero__content'>
      <h2 class='c-tag-hero__name'>{{ name }}</h2>
      <p class='c-tag-hero__description'>
        {{ description }}
      </p>
    </div>
</div>
    {{/foreach}}

{{/get}}

#3

I think you’re looking for the data attribute in your dynamic routing config:

:fire: tip: If you’re trying to see what data you have available in a given context, you can use the log helper - e.g. {{log this}} or {{log post}}


#4

Thanks for the reply, this is what I am after for sure. Can you give me an example of what my routes yaml would be to pull out the tag named properties? I am just not able to figure it out using the instructions. Or maybe there are more samples someplace. Here is what I have but I am stuck. This is my first Ghost project.

routes:
  /properties/:
    controller: channel
    filter: tag:properties
    template: properties
    data: 
      resource: tags

#5

You’re missing the property name (I converted it to the shortform structure outlined in the docs to make it simpler for you)

routes:
  /properties/:
    controller: channel
    filter: tag:properties
    template: properties
    data: 
      properties_tag: tag.properties

#6

Thank you. Now how do I get my data to show up in my template. I cannot get it to show anything. I know this may seem like I should be able to figure this out from the docs, but it just isn’t coming together for me. I really appreciate the help.

{{#tag}}
  <div class='c-tag-hero' style='background-image: url({{ img_url feature_image }})'>
    <div class='c-tag-hero__content'>
      <h2 class='c-tag-hero__name'>{{ name }}</h2>
      <p class='c-tag-hero__description'>
        {{ description }}
      </p>
    </div>
  </div>
{{/tag}}

#7

In the routes I provided, I set the name to properties_tag, so you need to do the same :wink:

{{#properties_tag}}
  <div class='c-tag-hero' style='background-image: url({{ img_url feature_image }})'>
    <div class='c-tag-hero__content'>
      <h2 class='c-tag-hero__name'>{{ name }}</h2>
      <p class='c-tag-hero__description'>
        {{ description }}
      </p>
    </div>
  </div>
{{/properties_tag}}```

#8

Thanks you very much. It is greatly appreciated.