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

    I have posted this to the forum in the past however was unable to come across a solution that worked.


    I am trying to find a way to make a snippet display as plain text on the page and not render on page load. That is I would like to display something like: [!Wayfinder?startId=`0` &firstClass=`first` &hereClass=``!] in a content area. I realise I could just put an empty space in there or an extra character such as [~!Wayfinder?startId=`0` &firstClass=`first` &hereClass=``!] and it would display as plain text and not render but this is not the ideal solution as I want to be able to copy and paste it quickly into the modx site that I am working on (this site is kinda like my library of modx tools)

    There is something already created for modx Revolution that does this (I think its called showSnippet.php), does anyone know of or could help point me in the direction of one that could work in Evolution?

    Thanks.
      • 20084
      • 25 Posts
      Just some more information.

      I am calling the snippet that I want to see via a template variable. Now I’ve discovered that if I do the following I kind of get the result that I want, but I’m not sure why its working and how to tweak it so its perfect.

      <pre>[!*snippet*]</pre>
      By putting the ! it produces the following result:

      [<div id="nav">[!Wayfinder?startId=`40` &firstClass=`first` &hereClass=`current` &level=`1`!]</div>

      Which is pretty much what I want, I want to see the html + the snippet call (not rendered) however as you can see there is a [ at the very beginning which I do not want.

      So to recap:
      1. Why does it seem to kind of work with the ! in the TV call
      2. How can I remove that [ from the output
      3. Is this a good solution to my problem?

      Thank You.
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        1: The ! specifies it shouldn’t be cached, but that’s not available for TV tags in Evolution AFAIK. So that might just indicate a parsing bug, lol.
        2: As 1 is unexpected behavior, I wouldn’t know how to correct it
        3: It seems to rely on something that shouldn’t work like that, so I’m going to say no.

        I would add a space in between the outer [ and the token (* or +). You could use a javascript to clue it back together on the front-end. You can also use <!-- --> as "divider" which is a HTML comment that stops the parser from parsing it, but doesn’t change the front-end display.


        In Revolution, you could use the "tag" output filter (which is like PHX on steroids built into the core) which displays the tag itself including parameters.
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 20084
          • 25 Posts
          Hi thanks for your response.

          I have thought of using some sort of breaking space like you suggested, however I am using this to make a library or resources so I want to preview how the snippet renders and then also the snippet itself in code that I can copy and paste from the site (I’m using the syntax highlighter copy function) and be able to use without having to edit the code (remove unwanted spaces). I want to only have to type the snippet up once and then call it in two different locations.

          I hope this makes sense.

          I should also note that I’m not a programmer, I mainly work with HTML and CSS and have sparse knowledge JavaScript.

          Thanks
            • 3749
            • 24,544 Posts
            If you put HTML comments in the right places, the code will display but not execute. You can cut and paste the code from the front end into an editor and the comments will be gone, so it will execute.

            HTML comment:

            <!-- -->


            Here is a converted tag (I’ve put extra spaces around the comments to make them easier to see -- they aren’t necessary);

            [<!-- -->   !   <!-- -->   Wayfinder?startId=`40` &firstClass=`first` &hereClass=`current` &level=`1`!   <!-- -->]


            There are also some plugins to do what you want. I think the best is FixedPre. The Evolution version is here:

            http://rahul.rahul.net/modx-hints/fixedpre-tag.html

            The Revolution version is here:

            http://modxcms.com/forums/index.php?topic=57209.0
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 3749
              • 24,544 Posts
              If you put HTML comments in the right places, the code will display but not execute. You can cut and paste the code from the front end into an editor and the comments will be gone, so it will execute.

              HTML comment:

              <!-- -->


              Here is a converted tag (I’ve put extra spaces around the comments to make them easier to see -- they aren’t necessary);

              [<!-- -->   !   <!-- -->   Wayfinder?startId=`40` &firstClass=`first` &hereClass=`current` &level=`1`!   <!-- -->]


              There are also some plugins to do what you want. I think the best is FixedPre. The Evolution version is here:

              http://rahul.rahul.net/modx-hints/fixedpre-tag.html

              The Revolution version is here:

              http://modxcms.com/forums/index.php?topic=57209.0
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 20084
                • 25 Posts
                Hi,

                I tried the fixedpre option and it didn’t work for me.

                I am using Evolution 1.0.4 would that make a difference?

                I can’t use the <!-- --> option as I’m using the syntax highlighter so it would actually display the <!-- --> in the output as they are in a <pre> </pre> wrapper.

                Cheers
                  • 3749
                  • 24,544 Posts
                  You did create the FixedPre plugin and attached it to the OnLoadWebDocument event, right?

                  If so, I think the problem might be with this line:

                  $modx->documentObject['content']=
                      preg_replace_callback("#(<fixedpre>)(.*?)(</fixedpre>)#s",
                      "quote_meta", $modx->documentObject['content']);
                  


                  $modx->documentObject is deprecated and may no longer be available in a plugin, but I’m not sure what the appropriate replacement would be for Evolution.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 4310
                    • 2,310 Posts
                    Just tried it with Evo 1.0.5 and it worked as expected smiley
                      • 20084
                      • 25 Posts
                      Quote from: bunk58 at Mar 10, 2011, 02:19 AM

                      Just tried it with Evo 1.0.5 and it worked as expected smiley

                      How did you do it?

                      I’ve created the plugin: plugin.fixedpre.tpl

                      // plugin.fixedpre.tpl -- implements <fixedpre> tag -- Rahul Dhesi
                      // http://rahul.rahul.net/modx-hints/fixedpre-tag.html
                      function quote_meta($a) {
                      $lhs = array("<", ">", "[", "]", "!", "{", "}", "`");
                      $rhs = array("&lt;", "&gt;", "&#091;", "&#093;", "&#033;", "&#123;", "&#125;", "&#96;");
                      $b = str_replace("&", "\255", $a[2]); //save "&"

                      $lhs_preg = array(’|<!(!*)fixedpre>|’, ’|<!(!*)/fixedpre>|’);
                      $rhs_preg = array(’<$1fixedpre>’, ’<$1/fixedpre>’);
                      $b = preg_replace($lhs_preg, $rhs_preg, $b);
                      $b = str_replace($lhs, $rhs, $b);
                      return str_replace("\255", "&amp;", $b); // restore "&"
                      }


                      $e = &$modx->Event;
                      if ($e->name == "OnLoadWebDocument") {
                      $modx->documentObject[’content’]=
                      preg_replace_callback("#(<fixedpre>)(.*?)(</fixedpre>)#s",
                      "quote_meta", $modx->documentObject[’content’]);
                      }


                      and ticked the OnLoadWebDocument option in the systems area

                      then called it using <fixedpre>[!Wayfinder?startId=`0` &level=`2` &hereTpl=`hereTpl`!]</fixedpre>

                      But its still outputting the actual menu ??