Reputation: 2989
So I have an object like this {"templateName":"myTemplate","data":{"one":1}}
Here is my template:
{templateName}
{>"{templateName}":data/}
This does not render though (with no error message)...however, it works when I change it to this:
{templateName}
{>"myTemplate":data/}
It renders like this in the view:
myTemplate
[then here it shows myTemplate, rendered with data passed to it]
It renders perfectly and even shows the correct template name on top. I thought that putting the key in the quotes would work, but I guess I am misreading the dustjs guide. How can I accomplish this?
Upvotes: 1
Views: 336
Reputation: 5609
After doing a little digging, I believe I have found the problem. By using the syntax {>"{templateName}":data/}
, you are changing the context from root
to data
. When this happens, templateName
is no longer accessible when Dust tries to resolve the template name. So, Dust ends up searching for a template called ""
. I have filed an issue for this bug.
Having said that, if I were to write a book called "Dust: The Good Parts", I would leave contexts out of it (e.g. {#myData:myContext}
). I have found that they cause more problems than they solve.
As a workaround, you can use this syntax:
{templateName}
{>"{templateName}"/}
And then your "myTemplate" would need to do something like:
{data.one}
Here is an example of this working.
Upvotes: 2