We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36755
    • 41 Posts
    Probably a modx beginner's question...

    Now I am using for all pages (code from template):

    <title>[*pagetitle*] | My-Site's-Name</title>


    However, the start page should be:

    <title>My-Site's-Name + some extra words</title>


    I know I could write a snippet, but maybe there is another way to have a switch (if-else=) within the template?

    Thanks for your knowledge.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Several solutions.

      1. Use something like [[++site_name]] - [[*pagetitle]] or [[*longtitle]] for the title - this is what I always use.

      2. Use a separate template for the home page. I do this if the home page is quite different from the inner pages. While it's fun to shoehorn an entire site into a single template, it's usually really not worthwhile in practice.

      3. Use an output modifier - not recommended, as it would be somewhat complicated and would take a lot more processing resources - every tag gets processed whether it gets used or not.
      [[*id:is=`1`:then:`[[++site_name]] - [[*longtitle]]`:else:`[[*pagetitle]] - [[++site_name]]`]]

      You could improve on this by putting the tags you want into two chunks, one for the home page and one for the other pages, then do this
      [[[[*id:is=`1`:then:`$homechunk`:else:`$pagechunk`]]]]

      Notice the doubled outer tags, and no tags around the chunk names; the output will end up either [[$homechunk]] or [[$pagechunk]], and then MODx will process the chunk tags on the next pass through the parser. This way, all four tags won't be getting processed whether or not they get used. But it still means that the modifier has to be processed, then the chunk, then the chunk's tags.
        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
        • 10208 ☆ A M B ☆
        • 1,780 Posts
        Is this site Evolution or Revolution? Your tags seem to point to it being Evolution, plus it's in the Evo forum. Is this a first install of MODX for you? If so, perhaps you will want to try Revolution instead, as there's some improvements and usability coolness with Revo. Plus then you could use Susan's examples (Revo tag syntax).
          Frogabog- MODX Websites in Portland Oregon
          "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
          Having server issues? These guys have MODX Hosting perfected - SkyToaster
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Hm. Didn't notice that. The output modifier solution would require the Phx plugin in the case of Evo.
            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
            • 9995
            • 1,613 Posts
            fourroses666 Reply #5, 13 years ago
            You can use the longtitle for that (or description or a new TV)
            PHx needs to be installed

            <title>[*id:is=`1`:then=`Site Name + [*longtitle*]`:else=`[*pagetitle*] | Site Name`*]</title>


            I use this allot:
            <title>Site Name / [*parent:isnot=`0`:then=`[*id:parent*] / `*][*pagetitle*] [*longtitle:is=``:then=``:else=`/ [*longtitle*]`*]</title> [ed. note: fourroses666 last edited this post 13 years ago.]
              Evolution user, I like the back-end speed and simplicity smiley
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Presuming that your site name is set in the System Settings, you can use [(site_name)] to get it.
                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
                • 36755
                • 41 Posts
                Thanks for all your feedback. I am on Evo.

                I had liked to use
                [[[[*id:is=`1`:then:`$homechunk`:else:`$pagechunk`]]]]
                , however, if it needs an extra plugin...

                So I will probably end up writing a tiny snippet that checks for the startpage...
                  • 36755
                  • 41 Posts
                  All right, I ended up creating a snippet called [!getpagetitle!]:

                  <?php
                  	$id = $modx->documentIdentifier;
                  	$pagetitle = $modx->documentObject['pagetitle'];
                  	if ($id==1) {  
                  		return 'My Site Name | '.$pagetitle;
                  	}
                  	else {
                  		return $pagetitle.' | My Site Name';
                  	}
                  ?>
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    You can use tags in content being returned, MODx will process them on the next pass through the parser:
                    return ($modx->documentIdentifier == 1) ? '[(site_name)] | [*pagetitle*]' : '[*pagetitle*] | [(site_name)]';
                      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
                      • 36755
                      • 41 Posts
                      ah thanks a lot, I was not sure about that smiley