We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23094
    • 59 Posts
    I have to generate some JavaScript code in my layout. I do it in my snippiet by placeholder:

    [....]
    $modx->setPlaceholder(’my_content’, $my_var->getPart(’content’));

    Problem is that $my_var->getPart(’content’) in placeholder is broken in places when double bracked is used "[[" (this fragment of code is cutted)
    I guess that there is any conflict in snippet when script try to generate double bracket what ModX use to set snippet name.
    What can I do to fix it? When I do it out of MODX in clean PHP it works fine.
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      It sounds like you’re trying to nest Snippets... one executes and generates a [[place_holder]], and then you’re expecting to run the Snippet referenced by that new placeholder... I don’t think that will work. At least, it’s a risky design... you end up relying heavily on precise execution order. I know you can use "{{chunk_name}}" as a value for a template variable, and the template variable get substituted first, and then the chunk is substituted second.

      Is there some other way for you to get the results you want without daisy-chaining Snippet names? In short, is there a way to get what you want without a Snippet outputting the name of another Snippet?
        • 23094
        • 59 Posts
        placeholder ’my_content’ generate JavaScript code like :

        "var dArr = [[’Monday’,[[’TH’,’Thursday’],......etc"

        it is third party JS code. Is it possible that MODx don’t like this brackets? How can I put this code to chunk rather than placeholder? I can’t find it in doc.
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          Well, I can think of 2 options:
          1. Change the placeholders in the Javascript from the default.
          2. Change the placeholders in MODx from the default.

          I think #2 would involve hacking the core... you could alter the core so that it would look for some other demarcator for placeholders, e.g. [%this%].

          If the Javascript library is well documented you might be able to change its placeholders... I don’t think [[ stuff is native javascript anything... it’s not like Perl where a "[ something ]" indicates an anonymous array...
            • 7231
            • 4,205 Posts
            I think the brackets are parsed out because modx thinks they are snippets (anything with [[ or [! is a snippet to modx and {{ a chunk and so forth..). I would put the javascript in a .js file and link it to the template.
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don't know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 23094
              • 59 Posts
              Quote from: Everettg_99 at Dec 15, 2008, 03:56 PM

              Well, I can think of 2 options:
              1.  Change the placeholders in the Javascript from the default. 
              2.  Change the placeholders in MODx from the default.

              I think #2 would involve hacking the core... you could alter the core so that it would look for some other demarcator for placeholders, e.g. [%this%].

              If the Javascript library is well documented you might be able to change its placeholders... I don’t think [[ stuff is native javascript anything... it’s not like Perl where a "[ something ]" indicates an anonymous array...


              The problem is that I can only ask server  by curl and API of third party application (I do it by snippet).  I receive from  server dynamically generated JavaScript code with JSON. I have to put it bottom of my HTML layout.
                • 22303 MODX Staff
                • 10,725 Posts
                Try something like this:
                $my_content = $my_var->getPart('content');
                $my_content = str_replace('[[', '[ [', $my_content);
                $my_content = str_replace(']]', '] ]', $my_content);
                $modx->setPlaceholder('my_content', $my_content);

                The extra whitespace will prevent MODx from trying to parse the brackets as snippet tags and should not affect the javascript execution...
                  • 23094
                  • 59 Posts
                  Quote from: OpenGeek at Dec 15, 2008, 06:05 PM

                  Try something like this:
                  $my_content = $my_var->getPart('content');
                  $my_content = str_replace('[[', '[ [', $my_content);
                  $my_content = str_replace(']]', '] ]', $my_content);
                  $modx->setPlaceholder('my_content', $my_content);

                  The extra whitespace will prevent MODx from trying to parse the brackets as snippet tags and should not affect the javascript execution...

                  It works like a charm now, thanks a lot everybody!!!