We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24865
    • 289 Posts
    Hi guys,

    I realise that this topic may have already been started and done with, but I still got the question and I can’t find a concrete answer.

    I am trying to create a small if statement like we would do in SMARTY, but I dont know if Revolution even has PHx or something native in it’s coding.

    This is what I am trying to do:
    [[+phx:if`[[*id]]`:ne=`[[+id]]`then:`<div class="footer-button"><a href="[[~[[+id]]]]">Read more</a></div>`]]

    Am I now completely off track or am I coming close?

    /edit
    I’ve started fiddling around with the If snippet from SplittingRed and it looks very promising but it doesn’t do what I expect it to do.
    [[If? &subject=`[[*id]]` &operator=`==` &operand=`[[+id]]` &then=`<div class="footer-button"><a href="[[~[[+id]]]]">Read more</a></div>` &else=`woot`]]

    Now, the above really should do this:
    if ($subject == $operand) {
    	echo '<div class="footer-button"><a href="[[~[[+id]]]]">Read more</a></div>';
    } else {
    	echo 'woot';
    }


    Although it does the exact opposite. I’ve got [[*id]] and [[+id]], which in the first page are 8 and 15, and in the second page are 15 and 15. Now, this would mean that the Read more button only displays when it’s not the same, but in fact, it’s the other way around. Am I doing something wrong?
      @MarkGHErnst

      Developer at Adwise Internetmarketing, the Netherlands.
      • 33337
      • 3,975 Posts
      Revolution has filters, a bit different syntax http://svn.modxcms.com/docs/display/revolution20/Input+and+Output+Filters

      You can also use IF snippet for conditionals. http://modxcms.com/extras/package/600

      Hope it helps.
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 895
        • 36 Posts
        [[*id:ne=`[[+id]]`:then=`<div class="footer-button"><a href="[[~[[+id]]]]">Read more</a></div>`]]

        +
        Input and Output Filters
          • 24865
          • 289 Posts
          I’ve just edited my post which would answer yours in place.

          I’ve taken a look at the input and output filters, but they do not support conditional statements like the If snippet does. Although the If snippet is giving me problems, this is the only one that comes pretty close to in fact being a solution.

          @Aleksey, I don’t see that on the filter page?

          /edit
          Oh shoot, I think I missed this line...
          [[element:modifier:anothermodifier=`value`:andanothermodifier:yetanother=`value2`]]  


          /edit
          I’ve entered your line Aleksey but it again does exactly the same as the If snippet, it changes the rules so to speak. Your filter does "if *id != +id then ...", while in fact it should be == instead of !=. Because when both IDs match on my page (15, 15) it shows the button and it does exactly the same on the first page.
            @MarkGHErnst

            Developer at Adwise Internetmarketing, the Netherlands.
            • 24865
            • 289 Posts
            This is pretty strange, even when I debug it as hell it doesn’t work:
            Conditional statement:
            ([[*id]], [[+id]])
            [[*id:ne=`[[+id]]`:then=`*id does not equal +id`:else=`or does it...`]]


            Page #1
            (8, 15)
            *id does not equal +id
            


            Page #2
            (14, 14)
            *id does not equal +id


            Help? Does the built in PHx perhaps read *id as an int and +id as a string? Is there a possibility to cast them both as ints then?

            /edit
            No.
            (string(2) "15" , string(2) "15" ) *id does not equal +id
              @MarkGHErnst

              Developer at Adwise Internetmarketing, the Netherlands.
              • 28215
              • 4,149 Posts
              Try:

              [[*id:if=`[[*id]]`:eq=`[[+id]]`:then=`equals it`:else=`doesnt`]]
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 24865
                • 289 Posts
                Quote from: splittingred at Jul 29, 2010, 08:02 AM

                Try:

                [[*id:if=`[[*id]]`:eq=`[[+id]]`:then=`equals it`:else=`doesnt`]]


                (string(1) "8" , string(2) "15" ) doesnt


                (string(2) "15" , string(2) "15" ) doesnt


                It could be because I am inside a chunk? Or shouldn’t that matter at all...? I just noticed that on my placeholder +content I cannot apply any of the mentioned modifiers. len returns 0, lcase returns nothing and so forth...

                I am loading my chunk with my own snippet using parseChunk.

                	if (!isset($tpl)) {
                		return 'I need a chunk template to work with';
                	}
                	
                	$id = $modx->resource->get('id');
                	$resource = $modx->getObject('modResource', $id);
                		
                	return $modx->parseChunk($tpl, $resource->toArray());
                  @MarkGHErnst

                  Developer at Adwise Internetmarketing, the Netherlands.
                  • 4172
                  • 5,888 Posts
                  try $modx->getChunk

                  parseChunk replaces the placeholders without processing.
                  getChunk does also outputfilter-processing and that.

                  this is new behavior in revo
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 24865
                    • 289 Posts
                    You rock my world!
                    That was it exactly. It now renders it perfectly and also says "equals it". Thanks a bunch. *crossed fingers not hoping to bump into more problems of this nature*
                      @MarkGHErnst

                      Developer at Adwise Internetmarketing, the Netherlands.
                      • 7327
                      • 195 Posts
                      Quote from: splittingred at Jul 29, 2010, 08:02 AM

                      Try:

                      [[*id:if=`[[*id]]`:eq=`[[+id]]`:then=`equals it`:else=`doesnt`]]


                      Do these conditions work out of the box in Revo, assuming the line above isn’t run by a Snippet but a direct call from a template or chunk?