We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16991
    • 0 Posts
    Hi all!
    Is there a way to change document’s pagetitle from snippet?

    Thanks in advance.
      • 33968
      • 863 Posts
      Yes, but that depends on exactly what you are trying to achieve.

      What do you mean exactly... do you want it permanently changed and updated in the database? Or just modified or formatted for the front-end?
        • 17422
        • 225 Posts
        
        $idDoc=l'id de ton doc;
        $pagetitle=nouveau page title à mettre;
        
        $doc=$modx->getObject('modResource',array(
            "id"=>$idDoc));
            $doc->set("pagetitle",$pagetitle);
            $doc->save();
        


        j’espère que ça va t’aider

        Laurent
          • 3749
          • 24,544 Posts
          And you need to tell us which version of MODX you’re using.
            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
            • 16991
            • 0 Posts
            I apologize for having provided so little information.

            I’m using MODx Evo 1.0.5.
            And I want to do the following thing:
            I wrote a snippet that gets some information from query string params passed.
            That snippet is called in document’s content.
            And I need to change that document’s pagetitle depending on query string.
            For example:
            if query string param is http://site.com?fruits.html?id=1
            I need that documents page title to become "Apples" and so on.
            There is no need to change the pagetitle in database, only to user.

            Excuse my English. I’m non-english speaker.
              • 33968
              • 863 Posts
              Excuse my English. I’m non-english speaker.
              Well, I’m English and I wouldn’t have noticed if you hadn’t said smiley

              All we need to know now is where you will get the ’Apples’ value from. Does ’id=1’ match up with ’Apples’ somewhere in your database?

              If you are able to get your snippet to return ’Apples’, you can either output it directly to the page where your snippet call is, or to a placeholder. Just place your snippet call or placeholder where [*pagetitle*] would normally be in your template.

              To output to placeholder [+newTitle+] from your snippet:
              <?php
              $title = 'Apples';
              $modx->setPlaceholder('newTitle', $title);
              return;
              

                • 4041
                • 788 Posts
                Maybe something like this:
                Create a new snippet with the code below named - ex: Fruit_title
                Replace your [*pagetitle*] call with the snippet call - ex: [!Fruit_title!]
                <?php
                $fruit = isset($_GET['fruit']) ? intval($_GET['fruit']) : '';
                
                switch($fruit){
                    case '1':
                        $output ='Apples';
                    break;
                
                    case '2':
                        $output ='Oranges';
                    break;
                    
                    case '3':
                        $output ='Bananas';
                    break;
                    
                    default: $output ='[*pagetitle*]';
                }
                
                return $output;
                ?>
                  xforum
                  http://frsbuilders.net (under construction) forum for evolution
                  • 16991
                  • 0 Posts
                  Thaks to all of you.

                  lucas, my snippet retrieves data from database.

                  The only problem I had was to replace [*pagetitle*] (and other global placeholders) in my document. I had not thought of using custom placeholders. Your example is what I really need.

                  Thanks again!