How do I access just the categories of a post? #2291
-
First, I am new to 11ty and I am just developing this blog (using liquid), so there is nothing beautiful about this - yet. How do I access just the categories of a post? Each of my posts is in a post_ I have a file This display is the two categories javascript and cats with no space between. This is ok, because I'll remove this line. I just wanted to see what What I really want is: Is there any easy way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 9 replies
-
It's most likely an array so you can do:
I loop over the list of categories, and if this is NOT the last item, add a comma and space. |
Beta Was this translation helpful? Give feedback.
-
I think the issue is that you said ---
# src/post_name.md
title: foo
categories:
- javascript
- cats
---
# {{ title }}
{{ categories | join: ", " }} OUTPUT<!-- www/post_name/index.html -->
<h1>foo</h1>
<p>javascript, cats</p> That should work if you just want a list of categories, but @cfjedimaster's solution of looping over the array of If you want to keep the file as |
Beta Was this translation helpful? Give feedback.
-
Given that you have a format of
This will slugify the category name (ie, "cool cats" to "cool+cats", or some such, it may be "cool-cats") creating a URL safe version of the category name. |
Beta Was this translation helpful? Give feedback.
-
Thanks, Peter.
I read both of your posts with interest. I don't know if I'll ever apply the information in your second comment, but who knows.
In the future, I may have use for the information in your first comment, but since you said, "
***@***.***(https://github.com/cfjedimaster)'s solution of looping over the array ofcategoriesis better if you want to display each category as a link" and I DO want to display them as links, I'll stick to ***@***.***(https://github.com/cfjedimaster)'s solution in this case.
Speaking of which, I don't know how to dynamically create the links to the category pages. Can you help? There is more information about this in my last response to ***@***.***(https://github.com/cfjedimaster).
Randall
Escolha o [ProtonMail](https://protonmail.com/) para apoiar a privacidade na internet e no e-mail.
|
Beta Was this translation helpful? Give feedback.
-
No problem. You got me over the hump I couldn't get over myself. That's what mattered.
Enviado via ProtonMail móvel
…-------- Original Message --------
On Mar 27, 2022, 17:27, Raymond Camden wrote:
Doh! Sorry about that. :)
—
Reply to this email directly, [view it on GitHub](#2291 (reply in thread)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AYNYPCQVOKPMLWKL7QLWZ4LVCDACHANCNFSM5RYVVFDQ).
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Given that you have a format of
/categories/NAME
, you can output it like so:This will slugify the category name (ie, "cool cats" to "cool+cats", or some such, it may be "cool-cats") creating a URL safe version of the category name.