We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36755
    • 41 Posts
    Maybe a newbie question?

    With friendly urls in modx evo, I use

    <h1><a href="[(site_url)][~[*id*]~]">[*longtitle*]</a></h1>


    in a template.

    However, as the root document has no alias (and I don't want to give it one to "stay" on root), I get this output:

    <h1><a href='mydomain.com/1'>Page title here!</a></h1>


    Is there any way to do that without a snippet?
      • 19369
      • 1,098 Posts
      I think you should use only this:
      <h1><a href="[~[*id*]~]">[*longtitle*]</a></h1>


      Do you have the base tag in your <head> section?
      <base href="[(site_url)]" />


      You may also use PHx plugin to hide the ID when the output is 1, for example:
      <h1><a href="[(site_url)][+phx:if=`[*id*]`:is=`1`:then=``:else=`[~[*id*]~]`+]">[*longtitle*]</a></h1>
      [ed. note: microcipcip last edited this post 14 years, 8 months ago.]
        • 36755
        • 41 Posts
        Thanks for your reply.

        As I always have full paths, I have not used the base tag yet. Will do so as this fixes my problem.

        Thanks for letting me know about PHx, it is new to me!


        I guess I will end up using though a little snippet that outputs the full url via:
        <?php
        $docID = $modx->documentIdentifier;
        if($docID==1) {
          return $modx->config['site_url'];
        }
        else {
          return $modx->makeUrl($docID, '', '', 'full');
        }
        ?>