We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11927
    • 105 Posts
    Is there a way to output the actual snippet call, instead of executing it?

    If you go here: http://bobsguides.com/modx-snippet-faq.html
    and then go to this question: "Why do I see the actual snippet call on the page instead of my snippet’s output?"

    The problem that Bob is addressing is exactly what I want to do.


    So instead of the snippet executing, how would I make the actuall call display on the page?

    i.e. display:
    [[snippet_call]]


    I tried htmlspecialchars, htmlentities. The only thing I can think of is creating a function that replaces the [[ ]] with the html equivilants. If there is a function that already does this, it would save me time and increase my php knowledge.
      You may or may not want to use the code I write. It's probably all against the syntax rules of php and MODx. smiley

      Carpet Cleaning
    • Do this, the comment tags will be hidden on your HTML page and your snippet call will be left visible:
      [<!-- -->[mySnippet? &myParam=`myValue`]<!-- -->]
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
      • I use HTML entites, &#91; and &#93; for example, instead of [ and ].
          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
          • 11927
          • 105 Posts
          Thank you for helping. I’ll probably use those ideas for creating a function.


          I’ve found that I never explain, what I’m trying to do, very well the first time I post a question on a forum.


          I’m creating a page, Page-See, that I can use to look at/view a Template (much like when you click edit in MODx, you see the snippet call).
          I have another page, Page-Do, that actually uses the Template and needs the snippet to execute.

          So I still want the snippet in the Template to execute on when I go to Page-Do that uses the Template, but just display the snippet call when I go to Page-See.



          Does that make sense? I may be trying to do something that is impossible.


          Maybe I’ll try creating a function to see if this will work.
            You may or may not want to use the code I write. It&#39;s probably all against the syntax rules of php and MODx. smiley

            Carpet Cleaning
            • 11927
            • 105 Posts
            So far I got this to work.

            After apply htmlspecialchars().

            I sent the Template to this function.


            <?php
            	function exchange_mod_chars($var_h)
            	{
            		// [ = [
            		// ] = ]
            		// { = {
            		// } = }
            		
            		$var_h = str_replace( '[', '[', $var_h);
            		
            		$var_h = str_replace( ']', ']', $var_h);
            		
            		
            		$var_h = str_replace( '{', '{', $var_h);
            		
            		$var_h = str_replace( '}', '}', $var_h);
            		
            		return $var_h;
            	}
            ?>



            If there is a function that php already has that does this, I would still be happy to know about it.
              You may or may not want to use the code I write. It&#39;s probably all against the syntax rules of php and MODx. smiley

              Carpet Cleaning
            • You could use the indexed array method (example 2) of preg_replace to do it all in one step

              http://www.php.net/manual/en/function.preg-replace.php
                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
                • 16278
                • 928 Posts
                I made a plugin and a wrapper snippet to demo Ditto calls on my Pogwatch site, which I think may meet your needs.

                The code is available at http://www.pogwatch.com/utility.html
                smiley KP
                  • 11927
                  • 105 Posts
                  Thank you so much.

                  I think I’m just barely starting to realize the power of both PHP and MODx.
                    You may or may not want to use the code I write. It&#39;s probably all against the syntax rules of php and MODx. smiley

                    Carpet Cleaning
                    • 3749
                    • 24,544 Posts
                    Bob’s guides has a custom snippet that’s frankly not good enough to share. It also uses the comment method.

                    There’s an excellent plugin in another thread that I would use if I were starting out now: http://modxcms.com/forums/index.php/topic,14042.0.html.

                    I posted a Revo version somewhere, but can’t find it.
                      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
                    • I’ve found it very useful to occasionally get a cup of tea and go to the PHP documentation, open up one of the categories (especially String Handling) and just read through it. There are a lot of things there that can save hours of trying to code the same functionality, plus the reader notes are also very instructional.
                        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