We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13736
    • 345 Posts
    I setup a link in my template to return to the parent document using

    <a href="[~[*parent*]~]">Return</a>


    It works good until it reaches the home page where it tries to link to document 0 instead of /index or 1. How should I be creating this "Parent" link?
      • 3749
      • 24,544 Posts
      You’ve done it correctly. The home page has no parent because it’s at the root so it’s parent is set to 0.

      If your page-not-found document is also the home page, a link to document 0 should take the user home.

      You could also put the home page under a container and set things up so that going to that container document forwarded the user to the home page.

      What I’d probably do is replace the [*parent*’] tag with a snippet tag. In the snippet, check the parent and if it’s 0, forward the user wherever you want, if not, return the parent ID.

      Hope this helps.
        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
        • 13736
        • 345 Posts
        I’m going to need some help with that last option. On a scale of programming skills, 1-10, I am a 1.
          • 4041
          • 788 Posts
          Maybe this will help smiley
          Create a new snippet named "get_parent_id" with the code below and replace the [*parent*] tag with the snippet call.
          ex: <a href="[~[!get_parent_id!]~]">Return</a>

          <?php
          // get_parent_id
          $output ='';
          $output = $modx->documentObject['parent'] != 0 ? $modx->documentObject['parent'] : $modx->config['site_start'];
          
          return $output;
          ?>
            xforum
            http://frsbuilders.net (under construction) forum for evolution