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

    Just making sure I’m not missing something big here.

    Am I right in saying that as soon as I come to a point in a template where I want to say (pseudo):

    if mytv=this then do that

    ... then I have to jump into php and therefore a snippit?

    I have several tvs, some of type image and some of type file. Depending on what’s been filled in and what hasn’t I need to render the output in different ways. I also need to check if the document has any children as that will alter the output dramatically.

    I tried a few things with snippits and am finding that getTemplateVars doesn’t do anything. That’s not really a problem though as I probably ought to pass this data in as parameters.

    Anyhow, as I said before, if its a conditional, does that mean a snippit and a bunch of php?

    Thanks in advance
      Hmmmmm.

      It's all a delusion
      • 8894
      • 114 Posts
      Hello,

      You can start with PHx plugin for your conditional statements: http://modxcms.com/PHx-1006.html
      But not sure it will fit all your needs.
        • 22303 MODX Staff
        • 10,725 Posts
        Yes, you can use phX or any other generic control snippet you want to do conditionals or loops, etc. The intention of MODx templating is simple and not the same as say Smarty, where code and markup have to be mixed: it’s to encourage the isolation of all logic from all presentation.
          • 1634
          • 51 Posts
          Quote from: enidan at Jan 24, 2008, 11:57 AM

          Hello,

          You can start with PHx plugin for your conditional statements: http://modxcms.com/PHx-1006.html
          But not sure it will fit all your needs.

          Great, thanks. Am taking a look now.
            Hmmmmm.

            It's all a delusion
            • 1634
            • 51 Posts
            Quote from: OpenGeek at Jan 24, 2008, 12:10 PM

            Yes, you can use phX or any other generic control snippet you want to do conditionals or loops, etc. The intention of MODx templating is simple and not the same as say Smarty, where code and markup have to be mixed: it’s to encourage the isolation of all logic from all presentation.

            Separation of code and logic is fine by me but there’s always a bit of crossover on web projects. Am making the transition from the lovely if slightly limited world of textpattern where you just go:

            <txp:if_custom_field .... >

            <txp:else />

            </txp:if_custom_field>

            Nice and easy. Am loving my ModX experience so far. Have had to get my head around porting tonnes of my
            jquery code to mootools for various reasons so am flying all over some steeeep learning curves..... with deadlines... ahhh. wink
              Hmmmmm.

              It&#39;s all a delusion
              • 7231
              • 4,205 Posts
              You can do the same thing with PHx like this:
              [+phx:if=`[+this+]`:is=`[+that+]`:then=`do this`:else=`do that`+]


              or with some data using placeholders and chunks:
              [+phx:if=`[*id*]`:is=`2`:or:is=`3`:then=`{{Chunk}}`:else=`{{OtherChunk}}`+]


              I don’t often use PHx (outside of snippets that include PHx functions like Ditto) I prefer to have a snippet (which is straight php) to do the logic and output accordingly. In MODx there is what I call the "chunk principle" where rather than having code in the format you describe where the actual code it surrounded by tags directly in the template, in MODx you will most likely have chunks representing the rendered output.

              http://wiki.modxcms.com/index.php/PHx
                [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                Something is happening here, but you don&#39;t know what it is.
                Do you, Mr. Jones? - [bob dylan]
                • 1634
                • 51 Posts
                Hi,

                Thanks for your replies. Got it working well using PHx. Its not the most elegant solution as I’ve ended up nesting sub PHx calls in chunks. Am being a bit ’quick n dirty’ about it really.

                Can PHx do something like this? :

                [+phx:if=`[*id*]`:is=`2`:or:is=`3`:then=`{{Chunk}}`:else:if:=`[*mytv*]`:is=`somevalue`:then=`{{OtherChunk}}`+]
                


                Notice this bit: :else:if:=
                  Hmmmmm.

                  It&#39;s all a delusion
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Excuse me on my soapbox this morning (I won’t stay on here long):

                  I think that crossover in web projects is simply because people don’t understand the implications that come with mixing logic and presentation. Or don’t yet fully see the benefits of completely isolating them.

                  Regardless, I’m cringing, just FYI, and begging people to keep such logic out of their content... why not just use Smarty if you want to get all complex like that? I prefer the concept of embedded templates (i.e. chunks) and simply author the necessary PHP logic to decide which chunk (or other MODx add-on) to present. Is it really any harder to write:
                  <?php
                  if (in_array($modx->documentIdentifier, array(2,3))) {
                      return $modx->getChunk('Chunk');
                  }
                  elseif ($modx->documentObject['mytv']['value'] == 'somevalue') {
                      return $modx->getChunk('OtherChunk');
                  }
                  ?>

                  And the performance benefits of this over the phX approach? Well, let’s just say you are likely adding more than 2 complete additional parser passes by using such phX logic vs. encapsulating it in a snippet. You are also losing complete control over the order in which any additional tags are parsed.

                  Just some thoughts that came to mind this morning; take it with a grain of salt... nothing more than my opinions here.
                    • 1634
                    • 51 Posts
                    Quote from: OpenGeek at Jan 25, 2008, 09:39 AM

                    Excuse me on my soapbox this morning (I won’t stay on here long):

                    I think that crossover in web projects is simply because people don’t understand the implications that come with mixing logic and presentation. Or don’t yet fully see the benefits of completely isolating them.

                    Regardless, I’m cringing, just FYI, and begging people to keep such logic out of their content... why not just use Smarty if you want to get all complex like that? I prefer the concept of embedded templates (i.e. chunks) and simply author the necessary PHP logic to decide which chunk (or other MODx add-on) to present. Is it really any harder to write:
                    <?php
                    if (in_array($modx->documentIdentifier, array(2,3))) {
                        return $modx->getChunk('Chunk');
                    }
                    elseif ($modx->documentObject['mytv']['value'] == 'somevalue') {
                        return $modx->getChunk('OtherChunk');
                    }
                    ?>

                    And the performance benefits of this over the phX approach? Well, let’s just say you are likely adding more than 2 complete additional parser passes by using such phX logic vs. encapsulating it in a snippet. You are also losing complete control over the order in which any additional tags are parsed.

                    Just some thoughts that came to mind this morning; take it with a grain of salt... nothing more than my opinions here.

                    That’s ok, I’m not precious and I always try value the opinions of others. Thanks for your input. This is my first ModX project so I am very open to suggestion.
                      Hmmmmm.

                      It&#39;s all a delusion
                      • 1634
                      • 51 Posts
                      Just to let you know. Adopted the snippit approach. Its much cleaner, easier to read and infinitely more extensible. Thanks for you help wink
                        Hmmmmm.

                        It&#39;s all a delusion