We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4342
    • 4 Posts
    I’m trying to create a way of dynamically detecting the page id or title then parsing a class onto the link.

    something along the lines of

    if($pagetitle=="Home") { echo ’class=\"current\"’; }

    but i am finding it very difficult to get the id of the page
    please can you help.
      • 7231
      • 4,205 Posts
      If you are using this to build a menu Wayfinder handles this automatically. If yo are using this to display documents, Ditto has this support built in as well.

      You can check the current page with the $modx->documentIdentifier function that will return the current document id

      $pageid = $modx->documentIdentifier;
      if($pageid=="1") { return 'class=\"current\"'; }
      
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 27376
        • 576 Posts
        All information about the current MODx document is available the [tt]$modx->documentObject[/tt] array. To access the pagetitle of the current document, use [tt]$modx->documentObject[’pagetitle’][/tt]. For future reference, do not expect to be able to change the document object and save it back to the database, this variable is essentially "read-only" and will exhibit unexpected results when you change any information in this array (due to caching and such).

        As a developer I have one recommendation: use the Document ID whenever you can. This number will never change for your document. You might decide later on to change the pagetitle and then you have to go back and change every occurrence of pagetitle comparison to match your new change. Quite a headache, I made that mistake only once wink
          • 4342
          • 4 Posts
          THANKS HUGELY!!!
          It’s working a dream and I’m racing through it all now!

          Amazing support !