We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19315
    • 84 Posts
    Hi,

    I’m trying to make a link in my template so that some pages link to the root, at /, and some pages link to some other page. A simple template variable seems the way to go here, with the id of the page to link to. However, I realise that I don’t know the id of the site root. I’ve tried 0 with no success.

    I can use the id of the document that is presented as the root (e.g. by using [(site_start)]), but as I am using friendly urls, the alias of the of that document ends up in the address bar, which I would prefer didn’t.

    Any suggestions?

    Michal.

    Edit: put in bit about [(site_start)])
      • 19315
      • 84 Posts
      Ok... I’ve found a way of getting the link. To make the URL, unstead of [~[*TVOfIDToLinkTo*]~] in the template, I make a small snippet
      <?php
      if ( $id == $modx->config['site_start'] ) {
        $output = $modx->config['site_url'];
      }
      else {
        $output = $modx->makeUrl($id);
      }
      return $output;
      ?>

      and I use &id=`[*TVOfIDToLinkTo*]` in the call to the snippet.

      Is there maybe a simpler way?
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        <a href="[(site_url)]"> maybe?
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 19315
          • 84 Posts
          Quote from: sottwell at Apr 09, 2008, 07:29 AM

          <a href="[(site_url)]"> maybe?
          That would give a link to the root, but on some other pages I would like a like to another document. Actually, my setup is more specific (which maybe I should have mentioned in my original post): this is (a simplified version of) my layout

          -Doc 1
          -Doc 2
          -Doc 3
          -Doc 4
          |-Doc 5
          |-Page 6

          On Pages 1 to 3, I would like the link to be to the site root, which is actually Doc 1, but without the alias of Doc 1 showing in the address bar. On pages 4 to 6, I would like a link to Doc 4. Now, having [(site_url)] would be good for pages 1 to 3, but would show the wrong link in Docs 4 to 6. I also looked into putting [!UltimateParent!]. This would be good for Docs 4 to 6, and Doc 1, but Docs 2 and 3 would link to themselves, and not to Doc 1 as I would like.

          I thought of just having a TV with the ID of the document to link to say TVOfIDToLinkTo, and putting [~[*TVOfIDToLinkTo*]~] in the link, but for links to the site root (which is doc 1), the alias of that document became part of the link. I tried treating the site root as doc 0, but that resulted in a "0" as the alias for the document in the link. Thus my TV+custom snippet solution.

          Michal.
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            I would use a TV with @INHERIT. The value for 1-3 would be 1 (or [(site_start)] maybe), the value for 4 would be 4, and all of its children would inherit that.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 36416
              • 589 Posts
              Quote from: sottwell at Apr 10, 2008, 04:53 AM

              I would use a TV with @INHERIT. The value for 1-3 would be 1 (or [(site_start)] maybe), the value for 4 would be 4, and all of its children would inherit that.

              maybe some devilish PHx tricks (if id = UltimateParent then site_start else UltimateParent) could be used to save from creating that TV...