We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5143
    • 116 Posts
    Is there some way to adjust the way template variables output data, so that they may be wrapped in appropriate html tags?

    Basically, I’ve added styling to all <p> tags in a certain section of a page, and I’d like there to be no empty paragraph tags as it would make things look a bit weird.
    I’ve read this http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+%28Output+Modifiers%29, but none of the defaults seem to address this.

    I’d happily write my own set of instructions, but I lack the necessary know-how.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Take a look at the documentation for phx; it’s a conditional output modifier for TVs and placeholders that’s built in to Revo.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 5143
        • 116 Posts
        Thanks for the very swift reply.

        I created a snippet called "pWrap" as follows:

        <?php
        return "<p>$input</p>";


        ...as I currently only need to render "p" tags around the content, and call each TV like so:

        [[*TVName:pWrap]]


        But I’m still getting empty paragraph tags around empty TVs, which I’m trying to eliminate - are they added in Modx Revo by default?
        Sorry - this is probably so simple to most people, but it’s all still quite new to me.

        Edit: Realised quite quckly that the problem lay with my previous snippet, not Modx, and consequently I think I may just written my first ever piece of conditional code!!

        <?php
        if (!$input) return"";
        else return "<p>$input</p>";


        I love how Modx gives you this "safe" environmet for putting code into place, even if I am (at best) a complete novice.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          I had something more in mind like
          [[*TVName:ifnotempty=`<p>[[*TVName]]</p>`]]

          But your pWrap could easily be modified:
          <?php
          if($input) {
           return "<p>$input</p>";
          } 
          return "";
          

            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 5143
            • 116 Posts
            laugh

            Thanks for that - I must’ve edited my previous message as you replied - looks a bit easier to decypher than my attempt.
            At least I know I was somewhere along the right lines.
              • 26016
              • 561 Posts
              Cool stuff. In my Revo, I’m not seeing any empty paragraph tags in my empty rich text TV’s. Go figure. smiley Tiny editor uses empty paragraph tags when you do extra carriage returns, so it could possibly be that. But I’m assuming you already thought of that.
                MODx and Wordpress development
                Linux, PHP 5.2, MySQL 5.0, Evo 1.05, Revo 2.08-pl, Firefox 4
                • 5143
                • 116 Posts
                Yeah, I’ve not got any richtext precisely for that reason.
                It was initially just a very badly written snippet which added p tags to anything - even empty fields.

                As exciting as it was to write my first piece of php, I’ll stick with the "notempty" method - I like the way it’s all contained in one line.