Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: tpl and renderTpl use cases

  1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    26
    Vote Rating
    1
      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
    39,551
    Vote Rating
    1271
      -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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

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

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    26
    Vote Rating
    1
      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
      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
    15
    Vote Rating
    0
      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,790
    Vote Rating
    391
      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
    398
    Vote Rating
    15
      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
    25
    Vote Rating
    27
      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
    25
    Vote Rating
    27
      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,790
    Vote Rating
    391
      0  

    Default

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

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •