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

Empty template returned #69

Closed
besi opened this issue Feb 13, 2014 · 3 comments
Closed

Empty template returned #69

besi opened this issue Feb 13, 2014 · 3 comments

Comments

@besi
Copy link

besi commented Feb 13, 2014

I have a text file which is my template for a message, that I want to compose.

Now I could get the template to work, but not with the builtin renderObject: fromResource: bundle: error: method.

So, this works

NSString *template = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FeedbackMailTemplate" ofType:@"txt"] encoding:NSUTF8StringEncoding error:NULL];
NSString *body = [GRMustacheTemplate renderObject:data fromString:template error:NULL];

but this doesn't work

NSString *body1 = [GRMustacheTemplate renderObject:data fromResource:@"FeedbackMailTemplate.txt" bundle:nil error:NULL];
NSString *body2 = [GRMustacheTemplate renderObject:data fromResource:@"FeedbackMailTemplate.txt" bundle:[NSBundle mainBundle] error:NULL];
@groue
Copy link
Owner

groue commented Feb 13, 2014

Hi @besi,

This is because the renderObject:fromResource:bundle:error: method expects a resource with .mustache extension (if not stated clearly enough in the documentation, I'll have to fix this).

So either rename your file to .mustache or .txt.mustache (some people do that), either use your first technique, and everything will be OK.

Should you eventually want to split your templates into sub-templates (called partials), while keeping the .txt extension, you may be interested in the GRMustacheTemplateRepository class. It can handle a set of partials with any custom file extension. Please refer to the Template Repository Guide, linked from the README file.

Happy Mustache!

@groue groue closed this as completed Feb 13, 2014
@besi
Copy link
Author

besi commented Feb 13, 2014

Wow thanks for the clarification. I will mustachen up my template then!

@groue
Copy link
Owner

groue commented Feb 13, 2014

Great! Thanks for the nice answer :-)

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

No branches or pull requests

2 participants