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

    I know it’s been asked a million times, and it’s a very common problem for people, but I have been looking around the forums trying possible solutions for the problem :

    When I try to call a snippet, all I get echo’d to the screen is the name of the snippet. For example :
    [!testingcontent? &content=`[+content+]` &parent=`[+parent+]`!]
    echo’s out in html
    [[testingcontent? &content=`blah blah blah` &parent=`24`]] 

    rather than the expected result from the snippet call.

    Strangely enough I have a working [[ditto_sitemap]] snippet that I have used to troubleshoot. Placing this [[ditto_sitemap]] snippet before or after [!testingcontent!] results in the sitemap working and the testingcontent not working. I believe that this has elimiated the rogue tags error (I am using extremely simple snippets, chunks, templates). I have also tried using non-cached and cached combinations, neither of which work.

    This has also effected me when trying to use WebLoginPE for my users. This has failed in exactly the same way, echoing out the snippet call rather than running it.

    This led me to believe that I had done something fundementally wrong, such as a speling mistake or not using backticks. I have checked these until I’ve gone mad and decided to make this post wink

    I have checked the following forum topics :
    http://modxcms.com/forums/index.php/topic,27987.0.html
    http://modxcms.com/forums/index.php/topic,27267.0.html
    http://modxcms.com/forums/index.php/topic,25775.15.html
    All of which they seem to be experiencing the same problem, but there is no conclusive solution!

    This led me further into thinking that perhaps some database corruption has occurred ? However when checking the site_snippets table I can see that the snippets have been entered in well and correct.

    Any other ideas where I can search for likely causes of corruption ? Or whether I am missing something fundemental ?

    Thanks in advance!
    David
      • 6725
      • 12 Posts
      Quick update :
      Realised that my snippet for WebLoginPE was called "WebLoginPE " (it had a trailing whitespace in it’s name). After correcting this the WebLoginSnippet worked for me. smiley

      However I still haven’t found out why the [!testingcontent? &content=`[+content+]` &parent=`[+parent+]`!] is not working.
        • 6725
        • 12 Posts
        Further update :
        The content that I was trying to echo out looked like this in the Document Editor (I don’t use the TinyMCE) :
        Does not work :
        Line 1<br />
        Line 2<br />
        Line 3<br />


        However if I then condense all of this onto a single line it does work :
        Line 1<br />Line 2<br />Line 3<br />


        I also noted that if you try to use any special characters (&amp; or &nbsp;) the call does not work, and neither does it work if you leave empty whitespaces or carridge returns at the end of the content section. eg this will not work:
        Line 1<br />Line 2<br />Line 3<br />
        
        
        

        and that you will need to delete all the ’empty returns’ to get it to work.

        Is this the same for everybody, or is it something that I’ve done / not done when setting up my ModX site ? Either way, I hope this helps someone else out who has been hitting their head against a brick wall! smiley

          • 15083
          • 697 Posts
          Would you not be better off dealing with the content inside your snippet?
          If you pass it in as a param there will be many cases where the data in [+content+] will break your snippet call?
            • 3749
            • 24,544 Posts
            Or put the content in a chunk, use the name of the chunk as a parameter, and have the snippet grab the chunk’s contents.
              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
              • 6725
              • 12 Posts
              Thanks jusmeig and Bob for your replies, however the site is designed for a non-technical end user that will create new news and will just about grab the concept of creating a new document in the right folder and writing in the content space!

              It just struck me as slightly strange that only [+content+] being used as a parameter would cause it to fall over when passed to a snippet, yet everything else works. Just one of those things I guess.
                • 3749
                • 24,544 Posts
                Sorry, I should have seen what you’re trying to do. If I understand it, you just want the current document’s content for use in your snippet. There are various ways to get it, but if you tell us why you want it, there might be a better way to do what you want.

                  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
                  • 6725
                  • 12 Posts
                  That’s exactly it! Initially the snippet was to parse whether there was anything contained within the content, and change the ditto’s custom template accordingly. (ditto outputs to the template chunk which calls the snippet, which in turn outputs back the template chunk)

                  After messing around with this, I figured it would be easier to @EVAL it in a template variabl, to determine whether there was any content, and pass that to the snippet instead, as a 1 or 0 is better than parsing the entire content. This failed too for some reason using the code :
                  @EVAL return (strlen([*content*]) > 2)? 1 : 0;


                  So instead I took a dive and created the template variable hasContent for the end user to fill it (it defaults anyway to 1) to determine whether or not there is content. It’s pretty messy but does the job without parsing the content or using an EVAL.
                    • 3749
                    • 24,544 Posts
                    It makes me wonder why you’d want to have published documents with no content.

                    Have you looked at Ditto’s &filter parameter? It should let you exclude documents with nothing in the content field.

                      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