A space in a Category name in a shortcode

I want to use a two word category name, but when I create a shortcode to get the latest post in that category, I can’t use a space in the category name in the shortcode. I tired fixes from old support posts with the same issue, but no luck.

How do I use “mail bag” in the shortcode instead of “mailbag”?

Post Frontmatter:

categories: ["Mail Bag"]

Shortcode mailbag-recent-post.html

<!-- mailbag-recent-post -->

{{ with site.Taxonomies.categories.mailbag }}
  {{ range first 1 . }} Read what's in the latest Mail:  
    <a href="{{ .RelPermalink }}">{{ .Title }}</a>
  {{ end }}
{{ end }}
{{ index site.Taxonomies.tags (urlize "Mail Bag") }}

Thanks, but

{{ index site.Taxonomies.categories (urlize "Mail Bag") }}
  {{ range first 1 . }} Read what's in the latest Mail:  
    <a href="{{ .RelPermalink }}">{{ .Title }}</a>
  {{ end }}

throws the error

execute of template failed at <first 1 .>

You forgot “with”

Ah, we both forget “with” :slight_smile:

This works. Thanks!

{{ with index site.Taxonomies.categories (urlize "Mail Bag") }}
  {{ range first 1 . }} Read what's in the latest Mail:  
    <a href="{{ .RelPermalink }}">{{ .Title }}</a>
  {{ end }}
{{ end }}

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