Print Param tags to DOM

Hi I have not been able to find the “correct” way to do this but I’m trying to use Tags to add posts to “categories” (News, Videos, etc.) which I want to use for a filtering dropdown, and to use as text labels on the DOM. In the front matter it looks like this:

category = ["News"]

and in the layout template I’m printing it like this:

<strong class="title">{{ .Params.category }}</strong>

Which works but it prints the category with brackets around it [News] so I believe I’m thinking about this the wrong way. I’m using Forestry and I need the user to be able to categorize new posts and Tags seemed to be the appropriate way. Any help getting me in the right direction to understand is appreciated. Thank you

edit: I should also probably add my config bits look like this:

  tag: tags
  category: category
  description: Blog
  - "News"
  - "Video"
  - "Update"

you could use range to iterate a slice/array.

{{ range .Params.category }}
<strong class="title">{{ . }}</strong>
{{ end }}

Thanks for your response! I have tried this and it still displays the brackets for some reason.

You are doing something wrong if the same brackets are still displayed. Either you changed it in the wrong template or at a location where .Params might refer to something else (don’t know what, but with just snippets and not the whole repo to look at we are working on a black box).

There is the command delimit which might help.

Hey this worked and removed the brackets! I looked at the docs and didn’t seen any specific way to only return the first item in the delimit list but that’s another problem. Thank you

That function is called index.

delimit is more for “concatenating” slices (arrays).

As annoying as it might be, a good start, if you have a weekend free, is to just page through the whole documentation. There is a lot of good features that are buried in it, most times in the code samples.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.