We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18397
    • 3,250 Posts
    (hey its 11:00PM here and I couldn’t think of a better title)

    In a discussion with vbrilon I discovered the following:

    [[test1? &val=`[!test3!]`]]


    Works, while:

    [[test1? &val=`[!test2? &val2 = `[[test3]]`!]`]]


    Does not.
      • 31337
      • 258 Posts
      I *think* the problem is with this code:
          preg_match_all('~\[\[(.*?)\]\]~', $documentSource, $matches);
      


      located in manager/includes/document.parser.class.inc.php line 682.

      But I could be wrong, tracing code flow on how snippets are eval’ed is proving to be a bit hairy smiley
        • 25663 MODX Staff
        • 12,272 Posts
        I’m guessing that the reason is the match only works once and is not recursive at all. Hence the discussion in the other thread.

        The reason the single-nested works with an uncached snippet is because it’s matching on a different syntax: [[ vs. [!.
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 24253
          • 125 Posts
          I discovered another somewhat similar one.

          The code was this:

          [!MenuBuilder?startID=[*lang*]!]

          Now I wanted to see what time it took to execute the MenuBuilder, or in fact, what happened if I _cached_ the page, and called it like:

          [[MenuBuilde?startID=[*lang*]]]

          This didn’t work, so I restored to the previous way of calling the snippet, after I cleared all the cached pages.

          Still, the problem was there that the [*lang*] call returned the wrong value!
          Could this probably come due code in siteCache.idx.php which isn’t refreshed?
          Should I make a bugreport?

          Greetz,

          Remon
            • 25663 MODX Staff
            • 12,272 Posts
            Sounds like a bug report to me Remon. Thanks.
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 32963
              • 1,732 Posts
              Hi Remon,

              Note you have [[MenuBuilde?startID=[*lang*]]] is that a typo?

              Also note that once you cache the page the [[]] will one be executed the first time the page is generated.

              Using [!!] when the page is cached will always execute the snippet code but [**] will remain a cached value.
                xWisdom
                www.xwisdomhtml.com
                The fear of the Lord is the beginning of wisdom:
                MODx Co-Founder - Create and do more with less.
                • 32963
                • 1,732 Posts
                Hmmm,

                I’m thinking that we could a custom syntax analyser that’s capable of looking through the code and executing each [[]] at a time.

                I’m thinking we could use strpos, substr and str_replace

                example:
                function name: mergeTag(&$html, $startpos=0)
                * let st = position of [[
                * if st>=0 then let et = position of ]] from st+2
                * let nst = position of [[ from st+2
                if nst < et then
                mergeTag($html,st+2)
                et = position of ]] from st+2
                end if
                if et>st then let tag = substr(st,et-st+2)
                $html = str_replace(tag,processTag(tag),$html)

                I’m not sure how fast this function would work but I think it will be able to process the tags in a the order they appear in the page.

                for example:

                [[A?
                &p1=`[[B? &p1=`[[C]]` ]]`
                ]]

                The execution order would be C, B then A

                What what you you think? Anyone want to give it a try?
                  xWisdom
                  www.xwisdomhtml.com
                  The fear of the Lord is the beginning of wisdom:
                  MODx Co-Founder - Create and do more with less.
                  • 24253
                  • 125 Posts
                  Quote from: xwisdom at Nov 11, 2005, 09:41 AM

                  Note you have [[MenuBuilde?startID=[*lang*]]] is that a typo?

                  I think yes ;-)

                  Quote from: xwisdom at Nov 11, 2005, 09:41 AM

                  Also note that once you cache the page the [[]] will one be executed the first time the page is generated.

                  Using [!!] when the page is cached will always execute the snippet code but [**] will remain a cached value.

                  Ah, I see. But even if [**] remains cached, the result is weird.
                  The result was that the value of [*lang*] for the cached page was from the other language folder, but to be sure I’ve to dig into it further.

                  And if the parser will change it’s parsing format, then this issue will probably vanish without the need looking into it smiley