I was hoping to use some config data (YAML) to dynamically specify another partial to render/include.
Handlebars' documentation suggests this is possible, like so:
{{> (lookup . 'myVariable') }}
See: http://handlebarsjs.com/partials.html
This however results in The partial could not be found.
I also found #195 and #239 regarding this.
I tried using the 'workaround' specified here but no luck: https://github.com/frctl/fractal/issues/239#issue-223851818
Is this possible?
Ah, more in depth instructions in #239 worked: https://github.com/frctl/fractal/issues/239#issuecomment-315387941
Would be good to fix the 'proper way' though.
Hi @iamkeir
This is definitely possible:
context: {
inputTemplate: '\\@input-pair'
}
.hbs file:{{>(lookup . 'inputTemplate') }}
Let me know if this helps.
@dkhuntrods yippee, thank you so much! Although it was actually a single backslash I needed in the end: \@input-pair - two slashes threw The partial \@input-pair could not be found.
Thanks very much - @tlenex will be pleased :)
I am. Thanks @dkhuntrods ! Only one \ (backslash) is required before @.
_Moved to https://github.com/frctl/fractal/issues/489 by @LeBenLeBen_
Is this also possible using the nunjucks-adapter?
Hi, I was wondering the same as @thomasaull. Has anyone managed this with nunjucks?
I'm doing it like this, maybe there's a nicer way though.
component.config.yml
context:
childTemplate: card--zoom
childContext:
foo: bar
component.nunj
{% render '@' + childTemplate, childContext %}
Thank you @LeBenLeBen. Works as intended!
@flepp, @LeBenLeBen Another way to do it is to set your childTemplate like \\@card--zoom and render it like
{% render childTemplate, childContext %}
Most helpful comment
Hi @iamkeir
This is definitely possible:
.hbsfile:Let me know if this helps.