BMF
BMF

Reputation: 307

concatenate Ext.XTemplate

I have a component I'm creating which has a template. I want to call a function in that template that returns another template, and concatenate that template inside the other. I'm not sure how to do this, because I'm just learning how to work with templates.

So this is a simple code like the one I want to do.

    myFunction: function (){
        return = new Ext.XTemplate(
            '<span>{name}</span>',
            '<span>{lastname}</span>',
        );

    }
    ....... //more code

    var Tpl = new Ext.XTemplate(
            '<tpl>',
                '<span>{title}</span>',
            '<tpl for="person1">',
                  {this.myFunction()},
            '</tpl>',
            '<tpl for="person2">',
                  {this.myFunction()},
            '</tpl>',
            '</tpl>'
        );

.... //more code

Any help would be really appreciated.

Thanks!

Upvotes: 0

Views: 250

Answers (1)

Sandu
Sandu

Reputation: 27

Here is an example of a template which is applied multiple times by another template:

var subTemplate = new Ext.XTemplate(
    '<b>Hello {.}!</b>'
)
var mainTemplate = new Ext.XTemplate(
    '<tpl for".">',
        '{[this.applySubTemplate(values)]}<br/>',
    '</tpl>',
    {
        applySubTemplate: function(name) {
            return subTemplate.apply(name)
        }
    }
)

console.log(mainTemplate.apply(['World', 'Foo', 'Bar']))

Upvotes: 2

Related Questions