Open quat1024 opened 3 years ago
There isn't a way to address "self" in mustache as far as I'm aware, so that was never part of the spec here either. I'd be happy to accept a PR that adds render_field_escaped
and render_field_unescaped
to String
and str
impls of Content
for a predefined faux field name, such as .
(so {{.}}
in templates).
Having slept on this, I think the proper way to do it is to expose sections to the same variable name as the main field in the map, so in your case that should be: {{#tags}}<a href="/post/tag/{{tags}}">{{tags}}</a> {{/tags}}
.
This would make loops analogous to how a single string works with existence checks. On the flip side, it will require a bit more messing around in the code.
So I'm making a personal blog site (surprise), and I wanted to add post tags. No problem, i'll add a field to my struct real quick.
Now to make a row of links to each tag. Let's see.
...I'm not sure how to name each item in the
Vec
. The section repeats 3 times if there are 3 elements in theVec
, but I don't know how to actually refer to the element, to make the sections different.I was able to solve it using a tuple struct, just because I can name the field
0
, like this.I'm a little bummed that I needed a useless tuple struct for this though. Is there a nicer way to do this?