Dynamic partials support
Closed this issue · 2 comments
Not sure if this is a moustache issue, node.js issue or Mu2 issue.
I'm using partials to include templates. For example:
home.mu
<p1>Welcome {{person}}</p1>
page.mu
<html>
{{> home.mu}}
</html>
Which works fine. But now I want to convert it so that I can pass the name of the template to include as a string in the view that is rendered. Like this:
var stream = mu.compileAndRender('page.mu', {
content: "home.mu"
});
And the modified page.mu template:
<html>
{{> content}}
</html>
But it does not work. Mu chucks an error at
DEBUG: TypeError: Cannot call method 'replace' of undefined
at Object.Parser (/Users/sensis/projects/Happiness Index/server/node_modules/mu2/lib/mu/parser.js:15:28)
at Object.parse (/Users/sensis/projects/Happiness Index/server/node_modules/mu2/lib/mu/parser.js:10:16)
at /Users/sensis/projects/Happiness Index/server/node_modules/mu2/lib/mu.js:37:21
I've also tried rendering home.mu separately, but I've not been able to figure out how to convert a stream to a string for inclusion in the view for rendering page.mu.
I suspect that I need to redesign this to all work asynchronously, but as I'm new to node.js, I've not been able to figure out how to do this.
Any ideas how to approach this?
Hey. So this is a mustache thing. The proper way to structure this
would be to have a header and footer that home.mu includes.
header.mu
footer.html
home.mu
{{> header.mu}}
Welcome {{person}}
{{> footer.mu}}
This has the benefit of also being about the stream the data to the
client as soon as possible without having to buffer the entire "inner"
part of the page in memory.
-Ray
On May 23, 2012, at 7:20 PM, Derek Clarkson
reply@reply.github.com
wrote:
Not sure if this is a moustache issue, node.js issue or Mu2 issue.
I'm using partials to include templates. For example:
home.mu
<p1>Welcome {{person}}</p1>
page.mu
{{> home.mu}}Which works fine. But now I want to convert it so that I can pass the name of the template to include as a string in the view that is rendered. Like this:
var stream = mu.compileAndRender('page.mu', {
content: "home.mu"
});And the modified page.mu template:
{{> content}}But it does not work. Mu chucks an error at
DEBUG: TypeError: Cannot call method 'replace' of undefined
at Object.Parser (/Users/sensis/projects/Happiness Index/server/node_modules/mu2/lib/mu/parser.js:15:28)
at Object.parse (/Users/sensis/projects/Happiness Index/server/node_modules/mu2/lib/mu/parser.js:10:16)
at /Users/sensis/projects/Happiness Index/server/node_modules/mu2/lib/mu.js:37:21I've also tried rendering home.mu separately, but I've not been able to figure out how to convert a stream to a string for inclusion in the view for rendering page.mu.
I suspect that I need to redesign this to all work asynchronously, but as I'm new to node.js, I've not been able to figure out how to do this.
Any ideas how to approach this?
Reply to this email directly or view it on GitHub:
#37
Thanks that will work. But it does mean that content pages have to include references to other content, which is something I was hoping to avoid. The concern (although a bit abstract at the moment) is that with larger and more complicated sites, this might not be workable.
I'll post this on moustache and see if they are considering it.