We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7970
    • 2 Posts
    Hey guys.

    Extremely newbie with both PHP and MODx so pardon my ignorance. Just started checking out MODx a few days ago... very impressed so far!

    but here’s a problem I’ve been trying to figure out: Can I modify the document content block from within a snippet?

    Basically what I’m trying to do is create some sort of a summary list on a sidebar of a page that is being populated from <h2> tags in my content, and linking each one of them to it corresponding location on the page. Extracting the content of those tags and wrapping it with an <a href="#..."> tag was pretty easy, but I can’t see a way to add matching <a name="..." title="..."></a> anchors into the content.
    This:

    $modx->documentObject[’content’] = preg_replace_callback($tagRegExp,"addAnchor",$modx->documentObject[’content’]);

    doesn’t seem to do anything.

    Any suggestions?
      • 32982
      • 674 Posts
      you need to make a querry to the database for this
      $modx->db->update...
        Jabiertxof (formerly XYZVISUAL)
        My bussines: http://marker.es
        https://www.youtube.com/user/jabiertxof/videos
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        If you need to do this dynamically, use a plugin. That can modify the page as it’s being parsed.
          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
          • 7970
          • 2 Posts
          Quote from: xyzvisual at Dec 21, 2006, 03:28 PM

          you need to make a querry to the database for this
          $modx->db->update...
          I might be wrong, but won’t that modify the content itself permanently? Won’t that also be a problem once the content is edited the next time, since some anchors are already there?

          Since I’ll have editors who are pretty much ignorant in HTML modifing that content, I’m trying to keep the content block as lean as possible.
          If I had the option of of some sort of an "array" of content blocks, I could’ve added the rest of my HTML code in templates, but since I have only one content block I think something more in the direction of a dynamic "pre-rendereing" processing would be more suitable.

          Quote from: sottwell at Dec 21, 2006, 03:29 PM

          If you need to do this dynamically, use a plugin. That can modify the page as it’s being parsed.
          From what I’ve read I’m starting to think that’s my only option... but in that case, I have two more questions:

          1. are there any such plugins already available somewhere, or should i start building one from scratch? Any pointers will be be appreciated.
          2. will I be able to use any caching on this page?

          cheers and thx for the quick reply.

          Edit: Ok, I think I found the answers to both questions. Cheers.