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

partial helper: use variable as partial name #46

Closed
scramatte opened this issue Dec 9, 2017 · 1 comment
Closed

partial helper: use variable as partial name #46

scramatte opened this issue Dec 9, 2017 · 1 comment

Comments

@scramatte
Copy link

Hi,

It would be nice to be able render a partial using a variable as helpernmae.
Currently helper doesn't make difference between "partialname" or partialname (without double quotes).

What I mean is considering following partials names:

  1. text
  2. textarea
  3. select
    ...

And a variable called type that can contains "text", "textarea" or "select"
I would like to be able to achieve the following
{{> type}}

And so partial helper should resolve properly name.
Regards

@nolimits4web
Copy link
Owner

Add support for dynamic helper names and partials using []:

Template7.registerPartial('input', '<input type="text">');
Template7.registerPartial('textarea', '<textarea></textarea>');
Template7.registerPartial('select', '<select><option>1</option><option>2</option></select>');

var template = `
  {{#each inputs}}
    {{> [type]}}
  {{/each}}
`;

var result = Template7.compile(template)({
  inputs: [
    {
      type: 'input',
    },
    {
      type: 'textarea',
    },
    {
      type: 'select',
    },
  ]
})

console.log(result);

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