Results 1 to 7 of 7

Thread: Templates within designer

  1. #1
    Sencha User
    Join Date
    Jun 2007
    Posts
    125
    Vote Rating
    1
      0  

    Default Templates within designer

    Is it possible to call functions within templates using the designer interface?

    I'm trying to do something simple (outside of the designer interface ) but struggling to find the right place within the designer if any.

    Displaying a list of images in an Ext.dataview.List based on a field value, while still displaying a default image if none is provided.

    outside the interface you can just include something like this
    Code:
    var tpl = new Ext.XTemplate(
        '<img class="photo" src="{ImageName:this.transformImage}" />',
        {transformImage: function(value){return Ext.isEmpty(value) ? 'placeholder.jpg' : value;}
    )
    but inside the interface anything pasted into the field is scrubbed for quotes and other characters.

  2. #2
    Sencha User aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,488
    Vote Rating
    147
      0  

    Default

    Look for coming changes which will greatly improve templates.

    When adding a template, you will get an additional node in the inspector. When clicking that node you will get a full blown code editor to edit your template's html.

    You can also add Basic Functions to that template node to add methods like you have suggested above. Currently the best solution would be to do this in a subclassed/overridden approach.
    Aaron Conran
    @aconran

  3. #3
    Sencha User
    Join Date
    Jun 2007
    Posts
    125
    Vote Rating
    1
      0  

    Default

    Thanks! I'm really looking forward to this one...

    Great job on the designer!

  4. #4
    Ext JS Premium Member smokeman's Avatar
    Join Date
    Jul 2007
    Posts
    475
    Vote Rating
    2
      0  

    Default explain further

    can you give an example of using the tpl config to add a function to that template?

  5. #5
    Sencha User
    Join Date
    Apr 2012
    Posts
    34
    Vote Rating
    3
      0  

    Default

    i'm also looking for this, can someone help us with some example?
    i would like to know how to call a function inside a tpl (like a the tpl in a list)

    can someone provide us/me an example?

    many thanks.

  6. #6
    Sencha User aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,488
    Vote Rating
    147
      0  

    Default

    The next minor version has the ability to add basic functions to individual templates.

    The current version, you must add these to Ext.util.Format and then invoke them.

    For example:
    Code:
    Ext.util.Format.yesNoFormat = function(bool) {
       return bool ? 'Yes' : 'No';
    };
    Then in the template
    Code:
    {isActive:yesNoFormat}

    If the function is directly added to the template itself you must prefix the function with this.
    Code:
    {isActive:this.yesNoFormat}
    Aaron Conran
    @aconran

  7. #7
    Sencha User
    Join Date
    Apr 2012
    Posts
    34
    Vote Rating
    3
      0  

    Default

    Thanks Aconran,

    I had to make it work

    Cheers~

    Thanks for your example

Posting Permissions

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