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
    Gainesville, FL
    Posts
    37,408
    Vote Rating
    851
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      -1  

    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
    ________________
    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 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.

  5. #5
    Sencha User
    Join Date
    Jan 2008
    Posts
    8
    Vote Rating
    0
    sarimarton is an unknown quantity at this point

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    renderTpl affects the component's structure. tpl affects the inner html when passing in the data config (or using the update method).
    What a great answer. Thank you very much!

  6. #6
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,611
    Vote Rating
    326
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      1  

    Default


    I've had a go at explaining the difference between tpl and renderTpl here:

    http://skirtlesden.com/articles/html...tjs-components

  7. #7
    Sencha User murrah's Avatar
    Join Date
    Oct 2007
    Location
    Katoomba, Blue Mountains, west of Sydney, Australia
    Posts
    387
    Vote Rating
    11
    murrah will become famous soon enough

      1  

    Default


    Quote Originally Posted by skirtle View Post
    I've had a go at explaining the difference between tpl and renderTpl here:

    http://skirtlesden.com/articles/html...tjs-components
    And a very detailed and helpful article it is too!

    Thank you.
    Murray