Results 1 to 5 of 5

Thread: XTemplate IF not working at all

  1. #1
    Ext User
    Join Date
    Jan 2008
    Posts
    103
    Vote Rating
    0
      0  

    Default XTemplate IF not working at all

    Here's my XTemplate declaration:

    Code:
    var _attachmentTpl = new Ext.XTemplate(
    	'<tpl for=".">',
    		'<div class="thumbwrap">',
    			'<tpl if=\'nothumb == "0"\'>',
    				'<div class="thumb"><img src="attachments/{issueid}/{iid}_thumb.jpg" /></div>',
    			'</tpl>',
    			'<div class="id">{iid}</div>',
    		'</div>',
    	'</tpl>');
    I have verified that the JsonStore attached to the DataView has been loaded with the correct data. There is currently only 1 item in the store. The item in the store has a nothumb value of "1" according to Firebug, which is correct. The template will render the <div class="thumb"> HTML block no matter what the value of nothumb is, which results in a broken image. I've looked at the API docs for this (a little inadequate) and I have searched the forums. My code should work, but it doesn't.

    I've also tried to use {nothumb} instead of just nothumb, same results.

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    128
      0  

    Default

    Try:
    Code:
    '<tpl if=\'values.nothumb == "0"\'>',

  3. #3
    Ext User
    Join Date
    Jan 2008
    Posts
    103
    Vote Rating
    0
      0  

    Default

    I'm still getting the same thing. It's as if the XTemplate is ignoring the IF conditions and just displaying everything.

    Here's my new code:

    Code:
    var _attachmentTpl = new Ext.XTemplate(
    	'<tpl for=".">',
    		'<div class="thumbwrap">',
    			'<tpl if=\'values.nothumb == "1"\'>',
    				'<div class="thumb"><img src="attachments/{issueid}/{iid}.{type}" /></div>',
    			'</tpl>',
    			'<tpl if=\'values.nothumb == "0"\'>',
    				'<div class="thumb"><img src="attachments/{issueid}/{iid}_thumb.jpg" /></div>',
    			'</tpl>',
    			'<div class="id">{iid}</div>',
    		'</div>',
    	'</tpl>');
    Both <div class="thumb"> blocks get rendered. I'm not getting any errors. Am I missing something? Is there anything to check to make sure the XTemplate is getting everything that it needs? Should I put a console.log within a [] block to execute within the template to make sure I'm getting the right values from my variables?

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    128
      0  

    Default

    <tpl if=""> MUST use double quotes!

    Code:
    var _attachmentTpl = new Ext.XTemplate(
    	'<tpl for=".">',
    		'<div class="thumbwrap">',
    			'<tpl if="values.nothumb == \'1\'">',
    				'<div class="thumb"><img src="attachments/{issueid}/{iid}.{type}" /></div>',
    			'</tpl>',
    			'<tpl if="values.nothumb == \'0\'">',
    				'<div class="thumb"><img src="attachments/{issueid}/{iid}_thumb.jpg" /></div>',
    			'</tpl>',
    			'<div class="id">{iid}</div>',
    		'</div>',
    	'</tpl>');

  5. #5
    Ext User
    Join Date
    Jan 2008
    Posts
    103
    Vote Rating
    0
      0  

    Default

    That works!

    Thanks for the help.

    Should the double-quote thing be mentioned in the API?

    EDIT: And also the values object is not mentioned anywhere. (i.e. values.nothumb)

Posting Permissions

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