We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12512
    • 42 Posts
    Hi all,

    In Evolution I used to be able to change the document title dynamically from a snippet using this code without that title being saved to the database:

    $modx->documentObject['pagetitle'] = "My dynamic title 123";


    I tried to do the same using the new Revolution API:

    $modx->resource->set('pagetitle', "My dynamic title 123");


    but this does not seem to work any more. Calling the $modx->resource-save() method does work but this changes the title also in the database permanently which is not what I want.

    How can this accomplished (version used is 2.0.4-pl2)?

      • 3749
      • 24,544 Posts
      I’m sure there’s another way, but this might do it:

      $modx->setPlaceholder('pagetitle','My dynamic title 123');
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 12512
        • 42 Posts
        Quote from: BobRay at Nov 13, 2010, 03:50 AM

        I’m sure there’s another way, but this might do it:

        $modx->setPlaceholder('pagetitle','My dynamic title 123');


        Thanks for that hint. I tried it out but like resource->set() it does not change the pagetitle. I have the feeling that the template already parsed the pagetitle template variable and therefore changing it in the content section it too late.

          • 3749
          • 24,544 Posts
          I think you could do it with a plugin tied to OnParseDocument, which fires just before the document is parsed. If you replace the pagetitle tag yourself before the page is parsed, the parser won’t see the tag.

          The content should be in this variable:

          $modx->documentOutput


          (or you could just try modifying that in your snippet).

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 10597
            • 31 Posts
            I do this by placing a placeholder in the title for the pages I want to have dynamic titles. In your snippets you can set it to what you want or it will appear blank.
              Using ModX Revolution
              • 3749
              • 24,544 Posts
              Quote from: geeble at Feb 11, 2011, 06:45 PM

              I do this by placing a placeholder in the title for the pages I want to have dynamic titles. In your snippets you can set it to what you want or it will appear blank.

              Great idea. I don’t know why I didn’t think of that. wink
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 37780
                • 1 Posts
                Bingo ! You saved my day dudes ! smiley
                  • 36564
                  • 17 Posts
                  Could you please write the final solution to setting the pagetitle dynamically?

                  I would like to set the pagetitle dynamically through a plugin and filling the pagetitle with a combination of three template variables.
                  • Why does it have to be the "pagetitle"? You can easily make a snippet to get the three TV values and format their output, then use the snippet tag where you were going to use the "pagetitle" tag. The snippet can even fall back to the pagetitle if the three TVs don't exist for that resource, or are empty.
                      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
                      • 36564
                      • 17 Posts
                      I already have the template variables displaying as the pagetitle on the rendered page.

                      I would like the pagetitle set to these three template variables to save filling it in again, and updating if one of those tvs are changed.