We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26074
    • 121 Posts
    Hi,
    I want create a back top system using an anchor to back top of the web page.

    I create a chunk BackTop with this code
    [[BackTop? &docid=`[+id+]`]]
    


    end the snippet BackTop with this code
    <?php
    $id = (isset($docid)) ? $docid: false;
    $output='';
    if(is_numeric($id)){
    $output = '<div class="back-top"><a href="' . [~$id~] . '#top">Back top</a></div>';
    return $output;
    }
    ?>
    


    but when I call the chunk in a page the output is this error:
    Parse error: syntax error, unexpected ’[’ in C:\xampplite\htdocs\dmsite\manager\includes\document.parser.class.inc.php(748) : eval()’d code on line 5

    I realize that error is [~$id~] in php code but how can I make the path of the link using modx api?

    Thanks


      ___________________________________________________________________
      ..:: Samuele ::..
      • 16732
      • 592 Posts
      This is not un chunk call, but a snippet call :
      [[BackTop? &docid=`[+id+]`]]


      And this, should be the snippet code:
      <?php
      $id = (isset($docid)) ? $docid: false;
      $output='';
      if(is_numeric($id)){
      $output = '<div class="back-top"><a href="' . [~$id~] . '#top">Back top</a></div>';
      return $output;
      }
      ?>


      Otherwise, for your problem try this
      Snippet call :
      [[BackTop]]

      Snippet code :
      <?php
      $output = '<div class="back-top"><a href="[~[*id*]~]#top">Back top</a></div>';
      return $output;
      ?>

        • 32319
        • 129 Posts
        Your error is from using a MODx variable [tt][*id*][/tt] in your php code (without putting it inside your quotes like laurentc said). If you want to get the ID in php you need to use this code:

        $modx->documentIdentifier;
        


        You can look here for more API functions and variables:

        http://wiki.modxcms.com/index.php/API:DocumentParser
          "Regret for the things we did can be tempered by time; it is regret for the things we did not do that is inconsolable."
          -- Sydney Harris
          • 26074
          • 121 Posts
          Thanks to all. Now work.
            ___________________________________________________________________
            ..:: Samuele ::..