1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    26
    Vote Rating
    0
    dougi is on a distinguished road

      0  

    Default tpl and renderTpl use cases

    tpl and renderTpl use cases


    Hi,
    I'm confused about the role of the tpl and renderTpl attributes. They can't be use together so i guess they do similar things.
    For what i know
    • tpl works with data and renderTpl. we can overwrite the content with the component's update method.
    • renderTpl works with renderData. We can overwrite the content with the XTemplate's overwrite method.
    When should we use one more the other? Have you got some use cases ?

    For instance, i want to create a custom component with some internal dom structure. I want to give the user the opportunity to update the content at runtime. Tpl seems fine. Am i wrong?

    i find nothing on the forum but if i am wrong feel free to redirect me.

    Thanks.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,710
    Vote Rating
    436
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    renderTpl affects the component's structure. tpl affects the inner html when passing in the data config (or using the update method).
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    26
    Vote Rating
    0
    dougi is on a distinguished road

      0  

    Default


    Hi,
    thanks but it does not help me that much. I'm currently looking at some Ext component source code to get the concept and come to the point that renderTpl is the solution for custom component.
    Besides that, i obviously miss something. Do you have a simple example where tpl could be used with renderTpl. The only example i can find so far with tpl is:

    Ext.create('Ext.Component', {
    renderTo: Ext.getBody(),
    tpl: new Ext.XTemplate(
    '<div class="product">',
    '<div>{name}:{desc}</div>',
    '</div>'
    ),
    data: {
    name: 'Product A',
    desc: 'Lorem ipsum dolor sit amet'
    }
    });

    Thanks again.

  4. #4
    Sencha User
    Join Date
    Jan 2012
    Posts
    26
    Vote Rating
    0
    dougi is on a distinguished road

      0  

    Default


    is it the way to use it.

    In my custom component, the inner structure is defined with renderTpl and populates with renderData.
    Code:
    renderTpl:[
      '<div>',
        '<div id="inner">',
          '{text}',
        '</div>',
      '</div>]
    Then when i instanciate the component, tpl give the opportunity to add a formatted html text inside my inner div. It's up to me to copy inside the component the generated content at the right place inside the inner div.

    Code:
    Ext.create('My.custom.Component', {
      data: {value:'hello world!'},
      tpl: ''<div><p><b>{value}</b></p></div>"
    });
    Am i right or i definitely miss something?

    Thanks.

Tags for this Thread