We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17162
    • 27 Posts
    Hello,
    I have a template with custom tv (dropdown list menu) I would like pagetitle to be automatically set to the chosen value from the dropdownlist when page is created.
    Is it possible to do and how?

    Thanks,
    Lina
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You could use a plugin using the OnDocFormSave event to grab the value of the TV and insert that into the database for the document’s title.

        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
        • 17162
        • 27 Posts
        Thank you for reply.
        I’m just studding it. smiley But, how can I limit it to only children pages of one page container?

        Lina
          • 6726
          • 7,075 Posts
          Very interresting I have a couple of cases where this feature could come in handy... sorry I can’t help with the PHP undecided
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l'outil id
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Have it do its thing only if the document does not already have a given title. If the document’s title is $_lang[’untitled_document’] (or $_lang[’untitled_weblink’]), that will trigger the replacement function.

            Looking at the save_content.processor.php file, I believe you could use the onBeforeDocSave event and check the value of $pagetitle and replace it if necessary in the plugin. No database action needed.

            Something like
            if($pagetitle == $_lang['untitled_document'] || $pagetitle == $_lang['untitled_weblink']) {
                $pagetitle = ??; // maybe $tmplvars['tvname'][1]
            }
            

            I’m still puzzlling over the save code for TVs to try to figure out how the TV data is passes in the POST. It looks like maybe &_POST[’tv’][’tvname’], but that can also be an array (in the case of select and check boxes), so it gets a bit tricky. I think it would be $tmplvars[’tvname’][1]...

            If you have a default, then all that goes out the window!
              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