We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6726
    • 7,075 Posts
    Recently, I wanted to add one of those accessiblity top menu bar on a MODx website I am building... I was faced with the need to set anchor links in my documents. I wanted only one chunk for the whole website and since anchor links are relative, I needed a way to generate the right path dynamically.

    Edit : Fixed according to Wendy’s tip below.

    Here is what I did : I use [~[*id*]~]#anchor

    Of course you’ll have to check your URL settings there : it will work with friendly URLs:Yes, Use friendly aliases:Yes, Use friendly alias path:Yes

    Sample chunk

    <ul>
    <li><a href="[~[*id*]~]#content" title="Directly access content">Go to content |</a></li>
    <li><a href="[~[*id*]~]#menu" title="Directly access menu">Go to menu |</a></li>
    <li><a href="[~[*id*]~]accessiblity/" title="Accessibility policy">Accessiblity policy</a></li>
    </ul>


    Hope you find this useful smiley

      .: COO - Commerce Guys - Community Driven Innovation :.


      MODx est l&#39;outil id
      • 33337
      • 3,975 Posts
      Thats great TIP ! grin

      Thanks for sharing this.. very usefull.

      regards,

      zi
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 5282
        • 147 Posts
        hi !
        but in my website this tip does not work with alias paths ..
        for example,
        the link will link to website.com/alias.html instead of website.com/pathtoalias/alias.html

        ( i used [(base_url)][*alias*] in the templates )


        p.s. i had added this tag in the pages header <base href="[(site_url)]" /> ( the dropmenu alias paths doesn’t work if i don’t )
          i’m not a native english speaker, sorry if there are any mistakes ! smiley

          Pikkitux.com Website about Ubuntu Linux, Website Creation, and many other how-tos, tips and tricks ... ( French Language, and of course Modx Powered ! )
          • 1186
          • 202 Posts
          Hello,

          I have also a problem using this tips :

          [(base_url)][*alias*]#anchor

          produces :

          http://www.mywebsite.com/alias#anchor

          instead of :

          http://www.mywebsite.com/pathtoalias/alias.html#anchor

          That means, "suffix" and "path" are not generated. Is this a MODx bug ?

            R
            • 32241
            • 1,495 Posts
            Why don’t you guys use this

            // FOR OTHER PAGE WITH SPECIFIC ID_NUM
            [~id_num~]#anchor1
            [~id_num~]#anchor2
            


            // FOR CURRENT PAGE
            [~[*id*]~]#anchor1
            [~[*id*]~]#anchor2
            
              Wendy Novianto
              [font=Verdana]PT DJAMOER Technology Media
              [font=Verdana]Xituz Media
              • 6726
              • 7,075 Posts
              Dumb me, I only tested this with a document at the root, not in subfolder...

              Wendy, not sure the [~[*id*]~] trick will do : I had asked here about that, and Jason said I’d have to use the id trick, but it didn’t cut it for me and I still have to find the right way to do it...

              Anyone ?
                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l&#39;outil id
                • 32241
                • 1,495 Posts
                David, it’s suppose to be work though. Imagine [*id*] is being parsed first, so it will be replaced with current doc id, and later [~~] will be parsed with the current doc id in the center. So if [~2~] or [~29~] work in your server, than [~[*id*]~] suppose to work as well. wink

                The only concern will be for people that are not using SEF, then the link will be index.php?id=2, so when you have [~[*id*]~]#anchorlink, then it will outputed index.php?id=2#anchorlink (will this work?).

                I haven’t tested this out yet, but by having a little knowledge on how the doc parser does his job, it’s suppoe to behave like what I explain in here.

                Sincerely,
                  Wendy Novianto
                  [font=Verdana]PT DJAMOER Technology Media
                  [font=Verdana]Xituz Media
                  • 6726
                  • 7,075 Posts
                  Hmmm, I’ll check that but I believe I have proper URL settings and I didn’t get the path with [~[*id*]~], only the file alias which I agree is strange.

                  I probably missed something specific to my config or did something wrong then. I’ll check and report.
                  Thanks !
                    .: COO - Commerce Guys - Community Driven Innovation :.


                    MODx est l&#39;outil id
                    • 1186
                    • 202 Posts
                    I have just tested the [~[*id*]~] trick, and... it works !

                    [~[*id*]~]#anchor gives me the right link, with the right subfolder path.

                    Many thanks to you.
                      R
                      • 6726
                      • 7,075 Posts
                      Ok thanks Wendy for the correction to my tip !

                      I have to check this now, since I am the culprit for it not working... grrr
                        .: COO - Commerce Guys - Community Driven Innovation :.


                        MODx est l&#39;outil id