Gokul Prabhu
Gokul Prabhu

Reputation: 132

How can I write custom handlebars in Ember js?

js:

Ember.Handlebars.registerHelper('demo-helper', function (property, options) {
    console.log('demo helper');
    return '<li><a> '+ msg+'</a></li>';
});

hbs :

{{#demo-helper}} msg {{/demo-helper}}

How can I wrap hi (inner html of handlebar) with any custom tag?.I know that component has tag parameter that encapsulates html with given tag. But it supports only one tag. I want to encapsulate with multiple tags like

<li><a>innerhtml</a></li>

Upvotes: 2

Views: 96

Answers (1)

AlexMA
AlexMA

Reputation: 10192

This is what components are for. They have can have an arbitrarily sized template. You can use {{yield}} to nest other html inside the component.

See https://guides.emberjs.com/v2.15.0/components/wrapping-content-in-a-component/.

component template:

<div><div><div>{{yield}}</div></div></div>

usage:

{{#my-component}} Hello world {{/my-component>}}

Components are very powerful and have many other options, see the guides for more info. They are the best resource.

Upvotes: 1

Related Questions