We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11858
    • 130 Posts
    I have a simple link like this:
    <a href="[~22~]">Image Gallery</a>
    

    Where "Image Gallery" is static. How do I change the "Image Gallery" text to the pagetitle of the page with the id 22? This is so the text will change dynamically should anyone change the name of the targeted pagetitle.

    Cheers

    A.
      • 4172
      • 5,888 Posts
      you can use Ditto

      [!Ditto? &documents=`22`&tpl=`mylink`!]


      chunk ’mylink’:
      <a href="[~[+id+]~]">[+pagetitle+]</a>


      or try (perhaps this does not work)
      [!Ditto? &documents=`22`&tpl=`@CODE:<a href="[~[+id+]~]">[+pagetitle+]</a>`!]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 22303 MODX Staff
        • 10,725 Posts
        The GetField snippet is a much better solution for this than Ditto, which IMO would be like using a 2-ton anvil to hammer in a thumb tack in this situation.
        <a href="[~22~]">[[GetField? &docid=`22` &field=`pagetitle`]]</a>

        Note that pagetitle is the default field value and that parameter is only shown here for clarity.
          • 11858
          • 130 Posts
          Brilliant. Thanks OpenGeek.