We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12410
    • 353 Posts
    Hi Guys,
    Trying to get if extra working in a chunk. Below code works fine in template.

    	<div class="listWrap">
    <h2>[[+pagetitle]] - Published on: [[+publishedon:strtotime:date=`%d-%m-%Y`]]</h2> 
    
    							
    [[!If?
    &subject=`[[*medImage]]`  also tried &subject=`[[+tv.medImage]]`
       &operator=`!equal`
       &operand=``
       &then=`
    <a href="[[~[[+id]]]]">
    
    <img class="imgMed" src="[[+tv.medImage:phpthumbof=`w=300&f=jpg&q=90`]]"/>
    
    </a>
    `]]
    
    [[+introtext:default=`[[+content:ellipsis=`550`]]`]]...<a href="[[~[[+id]]]]">Read More</a><div class='clear'> </div>
    </div>


    The conditional basically says that if there is no image selected for TV medImage then don't show the respective code that embeds the image. Its to prevent an empty image placeholder displaying. The above totally breaks the chunk code i.e no text content showing either outside the if statement.

    Any ideas please of changing the syntax. Works fine when embed in a template.Without the if statement the chunk renders fine.

    Thanks
    • Don't call If uncached in getResources tpl's. These chunks are already uncached and there is a bug preventing evaluation of the cached snippets in the uncached tag in 2.1.3.
        • 33968
        • 863 Posts
        Howster, I'm not sure but the problem might be your phpthumbof output filter - the backtick (`) is closing off the &then parameter and screwing up all the syntax after that.

        I'm not sure how much nesting you can get away with - especially with output filters - but you could try moving the image markup into another chunk and do this:
        <div class="listWrap">
            <h2>[[+pagetitle]] - Published on: [[+publishedon:strtotime:date=`%d-%m-%Y`]]</h2> 
         
            [[*medImage:notempty=`[[$medImage]]`]]
         
            [[+introtext:default=`[[+content:ellipsis=`550`]]`]]...<a href="[[~[[+id]]]]">Read More</a><div class='clear'>Â </div>
        </div>
        

        where [ [$medImage]] contains:
        <a href="[[~[[+id]]]]"> 
            <img class="imgMed" src="[[+tv.medImage:phpthumbof=`w=300&f=jpg&q=90`]]" />
        </a>
        


        Edit: just seen OpenGeek's response - I hadn't realised it was a getResources template but that makes far more sense wink [ed. note: okyanet last edited this post 12 years, 8 months ago.]
          • 12410
          • 353 Posts
          Thanks Guys, if cached worked. I tried it earlier and it didn't for some reason. Browser playing games on me I reckon.; Thanks for preserving my sanity on this one! smiley

          	<div class="listWrap">
          <h2>[[+pagetitle]] - Published on: [[+publishedon:strtotime:date=`%d-%m-%Y`]]</h2> <br />
          								
          							[[If?
             &subject=`[[+tv.medImage]]`
             &operator=`!empty`
             &operand=``
             &then=`
          <a href="[[~[[+id]]]]">
          <img class="imgMed" src="[[+tv.medImage:phpthumbof=`w=300&f=jpg&q=90`]]"/>
          </a>
          `]]
          
          
          
          
          [[+introtext:default=`[[+content:ellipsis=`550`]]`]]...<a href="[[~[[+id]]]]">Read More</a><div class='clear'> </div>
          </div>