SuperCuber / dotter

A dotfile manager and templater written in rust 🦀
The Unlicense
882 stars 46 forks source link

Dynamic self reference #56

Closed jakob-kruse closed 3 years ago

jakob-kruse commented 3 years ago

Environment

Arch Linux Dotter 0.12.1

The question

For example, I have the following section in my .dotter/global.toml

[foo.files]
"template" = "template.hbs"

[foo.variables]
"list" = [ "bar", "more-bar" ]
"bar" = "hello"
"more-bar" = "bye"

Now in the template file I want to iterate over foo.list:

{{#each list as | myProp |}}
{{/each}}

In that loop i want to get the variable inside foo. For example, foo[myProp] (when myProp is "bar") should render "hello".

I thought about using lookup for that, but I can't get it to work.

I tried doing (inside the loop)

{{ lookup @root.foo myProp }}

But that just renders nothing.

The following does work as intended, but the prop cant be dynamic

{{ ../prop }}

I know this is very specific, I'm sorry. Thanks

SuperCuber commented 3 years ago

I don't know too much about this kind of handlebars syntax either, but you could try using () for indirection, maybe something like {{(prop)}}... If that doesn't work you can try asking in handlebars-rs repo (i'd link it but I'm on mobile)