We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37693
    • 47 Posts
    Hi, I'm trying to emulate a basic elseif statement in my search results e.g:

    [[+img-thumb:notempty=`
    	<img src="[[+img-thumb:phpthumbof=`w=177&h=118&zc=1`]]">
    `:empty=`
    	[[+img-01:notempty=`
    		<img src="[[+img-01:phpthumbof=`w=177&h=118&zc=1`]]">
    	`:empty=`
    		[[+gallery-album:notempty=`
    				[[!Gallery? &album=`[[+gallery-album]]` &thumbWidth=`177` &thumbHeight=`188` &thumbTpl=`tpl-gallery-individual` &useCss=`0` &limit=`1`]]
    		`:empty=`
    			<img src="assets/images/placeholder.jpg">
    		`]]
    	`]]
    `]]

    I can't seem to nest 'empty/notempty' properly – just seems to return nothing or an erroneous character. I can do it to one level no problem e.g.
    [[+img-thumb:notempty=`
    	<img src="[[+img-thumb:phpthumbof=`w=177&h=118&zc=1`]]">
    `:empty=`<img src="[[+img-01:phpthumbof=`w=177&h=118&zc=1`]]">`]]

    Search call:
    [[!SimpleSearch? &tpl=`search-item` &pagingSeparator=`` &containerTpl=`search-container` &pageTpl=`search-pagination` ¤tPageTpl=`search-pagination-current` &noResultsTpl=`search-no-results` &highlightClass=`search-highlight` &includeTVs=`1` &highlightTag=`em` &perPage=`3` ]]


    Environment

    * PHP 5.3.6
    * Apache/2.2.21
    * OSX 10.6.8 (MAMP)
    * MySQL client version 5.5.9

    MODx:

    * Version: 2.2.0-pl2 (traditional)

    Cheers,
    Shaun
      • 37693
      • 47 Posts
      So I created an elseIf snippet:
      <?php
      $output = '';
       
      if ($op1 != '')  {
          $output = '<article>
      		<a href="[[+link:is=``:then=`[[~[[+id]]]]`:else=`[[+link]]`]]" title="read more about [[+longtitle:empty=`[[+pagetitle]]`]]" class="img-wrap">
      			<img src="[[+img-thumb:phpthumbof=`w=177&h=118&zc=1`]]">
      		</a>';
      } elseif ($op2 != '') {
          $output = '<article>
      			<a href="[[+link:is=``:then=`[[~[[+id]]]]`:else=`[[+link]]`]]" title="read more about [[+longtitle:empty=`[[+pagetitle]]`]]" class="img-wrap">
      				<img src="[[+img-01:phpthumbof=`w=177&h=118&zc=1`]]">
      			</a>';
      } elseif ($op3 != '') {
          $output = '<article>
      				<a href="[[+link:is=``:then=`[[~[[+id]]]]`:else=`[[+link]]`]]" title="read more about [[+longtitle:empty=`[[+pagetitle]]`]]" class="img-wrap">
      					[[!Gallery? &album=`[[+gallery-album]]` &thumbWidth=`177` &thumbHeight=`188` &thumbTpl=`tpl-gallery-individual` &useCss=`0` &limit=`1`]]
      				</a>';
      } else {
          $output = '<article class="no-image">';
      }
       
      return $output;


      And the call:
      [[!elseIf? 
      	&op1=`[[+img-thumb]]` 
      	&op2=`[[+img-01]]` 
      	&op3=`[[+gallery-album]]`
      ]]

      Unfortunately the incorrect statement seems to be applied to the results and the TVs aren't outputting anything.

      I know I'm being stupid, but would appreciate any help.

      Cheers.
        • 37693
        • 47 Posts
        There is an absolute abomination of a solution:

        [[!If?
           &subject=`[[+img-thumb]]`
           &operator=`!=`
           &operand=``
           &then=`<article>
        			<a href="[[+link:is=``:then=`[[~[[+id]]]]`:else=`[[+link]]`]]" title="read more about [[+longtitle:empty=`[[+pagetitle]]`]]" class="img-wrap">
        				<img src="[[+img-thumb:phpthumbof=`w=177&h=118&zc=1`]]">
        			</a>`
           &else=`
        	   [[!If?
        	      &subject=`[[+img-01]]`
        	      &operator=`!=`
        	      &operand=``
        	      &then=`<article>
        	   			<a href="[[+link:is=``:then=`[[~[[+id]]]]`:else=`[[+link]]`]]" title="read more about [[+longtitle:empty=`[[+pagetitle]]`]]" class="img-wrap">
        	   				<img src="[[+img-01:phpthumbof=`w=177&h=118&zc=1`]]">
        	   			</a>`
        	      &else=`[[+gallery-album:notempty=`
        	      	<article>
        				<a href="[[+link:is=``:then=`[[~[[+id]]]]`:else=`[[+link]]`]]" title="read more about [[+longtitle:empty=`[[+pagetitle]]`]]" class="img-wrap">
        					[[!Gallery? &album=`[[+gallery-album]]` &thumbWidth=`177` &thumbHeight=`188` &thumbTpl=`tpl-gallery-individual` &useCss=`0` &limit=`1`]]
        				</a>
        	     	`:empty=`<article class="no-image">`
        	      ]]`
        	   ]]
           `
        ]]


        Would much rather understand why my snippet is not working.
          • 1778
          • 659 Posts
          Why don't you use ifEval instead of this nested If ? http://modx.com/extras/package/ifeval

          Cheers