Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do partials work? #12

Closed
funston opened this issue Mar 11, 2010 · 7 comments
Closed

do partials work? #12

funston opened this issue Mar 11, 2010 · 7 comments

Comments

@funston
Copy link

funston commented Mar 11, 2010

i have a simple partial, template in the same dir.
tried both (where header.html.mu exists in the same directory as the main template.html.mu

{{foo}} {{header.html}}

nothing, works but doesn't include what is in header.html

@janl
Copy link
Owner

janl commented Mar 11, 2010

Partials do work, check out the examples in the examples/ directory as well as the docs in the Readme. mustache.js doesn't automatically load any files in the same directory (as JavaScript doesn't have any file-io :)

@funston
Copy link
Author

funston commented Mar 11, 2010

what does "automatically load any files" mean? so lets' say i have:

view.js
templates/header.html.mu
templates/body.html.mu

in view.js,i have : Mu.templateRoot = './templates';

then i render "header.html".

header.html.mu has

{{>body.html}}

but it never gets included. am i missing something? is there some directory path munging going on?

can you point me to a specific js example that runs a partial? I see the markup .html.mu but not any js that does anything with them...
thanks,
thanks....

@funston
Copy link
Author

funston commented Mar 11, 2010

oh, i see test.js. so are you saying that we must use readFileSYnc and do a compile of the template, versus doing render that has partials?

@funston
Copy link
Author

funston commented Mar 11, 2010

continued struggle. is there a simple example that runs under nodejs that uses partials in the templates?

@janl
Copy link
Owner

janl commented Mar 11, 2010

the key here is that you will have to have loaded all the template files from somewhere before calling to_html() and pass in all the template's contents:

var view = {
  partial: {
    foo: 1
  },
  name: "Jan"
};

var template = "Hi {{name}}. you have {{>partial}} foos.";

var partial_html = "{{foo}}";

Mustache.to_html(view, template, {
   partial: partial_html
});

@funston
Copy link
Author

funston commented Mar 11, 2010

/nevermind.

the problem was, my template had a

, which was blowing up the compiler....it apparently needs to be ' quotes:
in the partial...

@xoundboy
Copy link

the key here is that you will have to have loaded all the template files from somewhere before calling to_html() and pass in all the template's contents:

var view = {
partial: {
foo: 1
},
name: "Jan"
};

var template = "Hi {{name}}. you have {{>partial}} foos.";

var partial_html = "{{foo}}";

Mustache.to_html(view, template, {
partial: partial_html
});

... I think you should add this to the documentation - I spent over an hour scratching my head over why partials didn't work - I like simple and clear documentation as much as anyone but not at the expense of leaving out essential information on how to use a basic functionality

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants