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

      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    38,814
    Vote Rating
    1168
    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

      -2  

    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 Software Engineer
    ________________
    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
    1
    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
    1
    dougi is on a distinguished road

      1  

    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
    14
    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,789
    Vote Rating
    384
    skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute

      3  

    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
    397
    Vote Rating
    15
    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

  8. #8
    Sencha User
    Join Date
    May 2011
    Posts
    22
    Vote Rating
    27
    Decoy Deluxe will become famous soon enough Decoy Deluxe will become famous soon enough

      0  

    Default

    @skirtle - great resource, thanks a lot. There's one thing that's puzzling me about renderTpl vs tpl:This component renders as you would expect
    Code:
    {     xtype : 'component',     id : 'moose',    renderTpl : '{% this.renderContent(out, values) %}',    tpl: '{name} is {age} years old and lives in {location}',     data: {     age: 26,     location: 'Italy',     name: 'Mario' }                                 }
    => "Mario is 26 years old and lives in Italy

    "But when I call update
    Code:
    Ext.getCmp('moose').update({             age: 7,             location: 'Japan',             name: 'Aimee'         })
    ==> "Aimee is 7 years old and lives in Japan"The from the renderTpl has disappeared (along with any defined childEls references). Mitchell said above that the update method affects the tpl only, so I expected to be able to call update without killing the renderTpl.what am I doing wrong?Thanks guys.

  9. #9
    Sencha User
    Join Date
    May 2011
    Posts
    22
    Vote Rating
    27
    Decoy Deluxe will become famous soon enough Decoy Deluxe will become famous soon enough

      0  

    Default

    Oh crikey, the forum stripped my html tags, even in the code blocks!?Anyway, the renderTpl has H3TAG - content - ENDH3TAG - 1st render has content within h3 tags - update removes the h3 tags leaving content 'naked'I'm sure you get the drift

  10. #10
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,789
    Vote Rating
    384
    skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute skirtle has a reputation beyond repute

      0  

    Default

    You haven't implemented getTargetEl so update will be treating el as the target.