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

Feature Request: Pass context object to functions section #677

Open
abdulkareemnalband opened this issue Sep 26, 2018 · 0 comments
Open

Comments

@abdulkareemnalband
Copy link

Pass context object to function section as third argument

This allows me to implement limited template inheritance. without changing spec mustache/spec#38

Example

Base Template

<html>
<head>
   {{#title}}<title>{{title}}{{/title}}
</head>
   <body>
     {{content}}
   </body>
<html>

And Final template like

{{#baseTemplate}}
   <div>Hi {{name}}</div>
{{#baseTemplate}}

And javascript like

function renderBase(){ 
  return function renderBaseInternal(text,renderFn,context){
    // I propose pass context as third argument
    const content = renderFn(text);
    const new context = context.push({content:content});
    return mustache.render(baseTemplate,newContext);
} 

const data = {
  title:'Awesome title',
  name:'Horton',
  baseTemplate:renderBase
};
const finalRender = mustache.render(finalTemplate , data);

}
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

2 participants
@abdulkareemnalband and others