We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38205
    • 11 Posts
    I apologize if this has been answered before (believe me ive looked) but im new to MODx and im curious is there and way to add a simple line of php code to your resource without creating a whole new snippet for it?

    Creating a snippet for every time i want to write something like <?php echo "hello world" ?> seems a bit tedious.

    Thanks in advance!
      • 28120
      • 380 Posts
      Don't think so, but once you've created a one line snippet it's no more tedious to subsequently write

      [[!helloWorld]]
        • 22303 MODX Staff
        • 10,725 Posts
        Or even better; reusable even:

        Snippet:
        <?php
        echo $input;


        Usage:
        [[echo? &input=`helloWorld`]]
          • 32316
          • 387 Posts
          I'm interested in what:
          something like <?php echo "hello world" ?>
          is since it seems as easy to type
          "helloWorld"
          as:
          <?php echo "hello world" ?>
          or
          [[echo? &input=`helloWorld`]]

          At any rate writing a snippet is easy, quick and reusable - and, perhaps most importantly you know where to look for your php code and it is not going to be mixed in with your content or in the template - this is good on many levels
            • 38205
            • 11 Posts
            Quote from: whistlemaker at Jan 04, 2012, 09:20 AM
            I'm interested in what:
            something like <?php echo "hello world" ?>
            is since it seems as easy to type
            "helloWorld"
            as:
            <?php echo "hello world" ?>
            or
            [[echo? &input=`helloWorld`]]

            At any rate writing a snippet is easy, quick and reusable - and, perhaps most importantly you know where to look for your php code and it is not going to be mixed in with your content or in the template - this is good on many levels

            I was thinking like wrapping html in if statement and such. Like

            <?php if(1==1){ ?> Hi <?php } ?>
              • 33968
              • 863 Posts
              You can use Output Filters for that.

              [[*tag:is=`1`:then=`Hi`:else=`Bye`]]
              
                • 9102 ☆ A M B ☆
                • 318 Posts
                For slightly more complicated cases such as this, you can use the If snippet and put the HTML in chunks.