1. #1
    Ext User
    Join Date
    Apr 2008
    Posts
    418
    Vote Rating
    0
    pokerking400 is on a distinguished road

      0  

    Default [SOLVED] : if else in Ext.XTemplate

    [SOLVED] : if else in Ext.XTemplate


    Hi,

    I am trying to show different thumbnail for video and images.

    Now there is some syntax error. Can someone help with this?.

    Thanks.

    Code:
     myexpander= new Ext.grid.RowExpander({
    tpl: new Ext.XTemplate(
    '<p>',															'<tpl if="mediatype==image">',
    '<p><img src="'+Ext.webhost+'/media/{property}/images/{medianame_file}" width="100" height="75"  ></p>',
    '</tpl>',
    '<tpl if="mediatype==video">',
    '<p><img src="'+Ext.webhost+'/media/video.jpg" width="100" height="75"  ></p>',
    '</tpl>',
    '</p>'
    )
    });
    Image and video are strings. mediatype is column value

    I think it is problem of comparing to string. It is assuming video and image as column.

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,505
    Vote Rating
    53
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    It needs quotes, otherwise it's gonig to compare it to the image property rather than the string "image".

  3. #3
    Ext User
    Join Date
    Apr 2008
    Posts
    418
    Vote Rating
    0
    pokerking400 is on a distinguished road

      0  

    Default


    Still nothing!. No error though. Just blank except the filename text i added last to indicate everything works except template if else.

    Code:
    myexpander= new Ext.grid.RowExpander({
    tpl: new Ext.XTemplate(
    '<p>',
    '<tpl if="mediatype=='+"'image'"+'">',
    '<p><img src="'+Ext.webhost+'/media/{property}/images/{medianame_file}" width="100" height="75"  ></p>',
    '</tpl>',
    '<tpl if="mediatype=='+"'video'"+'">',
    '<p><img src="'+Ext.webhost+'/media/video.jpg" width="100" height="75"  ></p>',
    '</tpl>',
    '</p>',
    '<p>{medianame_file}</p>'
    });

  4. #4
    Ext User
    Join Date
    Apr 2008
    Posts
    418
    Vote Rating
    0
    pokerking400 is on a distinguished road

      0  

    Default


    Infact it works. mediatype is combo box. I need to compare with combobox values not the display value.

    Here is the image of my grid.


  5. #5
    Ext User
    Join Date
    Apr 2008
    Posts
    418
    Vote Rating
    0
    pokerking400 is on a distinguished road

      0  

    Default


    close this.

  6. #6
    Sencha User
    Join Date
    Feb 2013
    Posts
    1
    Vote Rating
    1
    Kimi05 is on a distinguished road

      1  

    Default


    see if these examples help


    '<tpl if="id == \'download\'">...</tpl>',
    "<tpl if='name == \"Don\"'>Hello</tpl>"

Thread Participants: 2