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

Does jSmart support include and extends? #13

Closed
AceMood opened this issue May 16, 2015 · 4 comments
Closed

Does jSmart support include and extends? #13

AceMood opened this issue May 16, 2015 · 4 comments

Comments

@AceMood
Copy link

AceMood commented May 16, 2015

It seems that getTemplate method always return throwing an error.

@iancj
Copy link

iancj commented May 22, 2015

Yes, I also met the same problem.How can I fix this ?

@umakantp
Copy link
Owner

Can you share your code please?

@akshay-since1987
Copy link

@iancj @AceMood @umakantp

I think this issue arises because we try to give path relative to the current template while jSmart expects it to be relative to the project. I fixed it by using the code below to over-ride the default include method.

I could do this since I had a very simple Project structure where src/templates/pages contained the current template and src/templates/components contained the template to be included in the current template. I hope this helps.

P.S.: I had to write this code in a place where i had access to variable called file which is the path to the current template.

jSmart.prototype.registerPlugin(
'function',
'include',
function(params, data)
{
var contents = "";
if(path.isAbsolute(params["file"])) {
contents = fs.readFileSync(params['file']);
} else {
var dirName = path.dirname(file); // This is the path of the current template inside the root directory of my project
var filePath = path.resolve(dirName, params["file"]);
contents = fs.readFileSync(filePath, {encoding: 'utf-8'});
}
return contents;

});

@umakantp
Copy link
Owner

This has been fixed in the release v2.15.1

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

4 participants