We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14956
    • 7 Posts
    I’m using the new MODx Revolution 2.0.2-pl
    I’m just trying to call a snippet from within a snippet. They look like below
    I get this:
    Parse error: syntax error, unexpected ’[’ in C:\xampp\htdocs\cmapp\core\cache\elements\modsnippet\2.include.cache.php on line 7


    Snippet1:
    [[Snippet2]]


    Snippet2:
    if ($modx->user->isMember(’SuperUser’)) {
    return ’3’;
    }
      • 1778
      • 659 Posts
      Try

      Snippet1
      $snippetName = 'mySnippet';
      $modx->runSnippet($snippetName);
      
      // OR if you have parameters in your snippets you can pass them as an array and do
      $modx->runSnippet($snippetName,$parameters);
      


      Cheeers
        • 14956
        • 7 Posts
        Snippet1 displays nothing. Snippet2 displays "3".
        As below.

        Snippet1:
        $runcheck = "Snippet2";
        $modx->runSnippet($runcheck);

        Snippet2:
        <?php
        if ($modx->user->isMember(’SuperUser’)) {
        return ’3’;
        }
          • 14956
          • 7 Posts
          Does anyone know how to do this or how to make something like this work?
          I don’t want to have to write a bunch of checks into each snippet, I’d rather call another snippet. I’d like to assign a variable in my script based on a snippet return.
            • 4172
            • 5,888 Posts
            Snippet1:
            <?php
            $runcheck = 'Snippet2';
            return $modx->runSnippet($runcheck);


            or:
            <?php
            $runcheck = 'Snippet2';
            $output = $modx->runSnippet($runcheck);
            return $output;
            


            Snippet2:
            <?php
            if ($modx->user->isMember('SuperUser')) {
              return '3';
            }
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 14956
              • 7 Posts
              I really hate it when the answer is that easy. I should have noticed the missing return.
              Thanks for your help!