We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4369
    • 31 Posts
    Hello again!
    I’m starting to really like this cms!!

    Can I use conditions in the templates?
    I want to use them for several cases, but the most current one of them is for the html title of the page.
    I want the title of the page to be in the next format:
    If I’m in a page with no children or on a parent page, I want the title to be "Pagename".
    But if I’m in a child page, I want the title to be "ParentPageName | ChildPageName".

    So I thought about checking if the page has parents ([*parent*] > 0) and then act according to the results.
      • 10487 MODX Staff
      • 1,535 Posts
      Hi buzi,

      You won’t be able to use that kind of logic in a template, however you could write a short snippet to get the same results.

      For the example you gave above, this should work (just call the snippet within the <title> tag):

      if ($modx->documentObject['parent'] > 0) {
      	$parent = $modx->getParent();
      	$output = $parent['pagetitle'] . ' | ' . $modx->documentObject['pagetitle'];
      } else {
      	$output = $modx->documentObject['pagetitle'];
      }
      
      return $output;
      


      Hope that helps,

      Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 4369
        • 31 Posts
        Wow great! It’s working fabulous!

        But now I have a completely diffrent question:
        How do I get the site URL inside a snippet ?
        The DropMenu is giving me a relative path to the children pages, and I’m using friendly URLs, so if I’m inside a child page, and I click on it again or one of it’s "friends", I get a 404 page.
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: buzi at Jun 08, 2006, 05:01 AM

          But now I have a completely diffrent question:
          How do I get the site URL inside a snippet ?
          The DropMenu is giving me a relative path to the children pages, and I’m using friendly URLs, so if I’m inside a child page, and I click on it again or one of it’s "friends", I get a 404 page.

          Search for the following terms in the main search page for the forums -- friendly alias path base href

          There are many posts about using friendly alias paths and a single template; here’s one of the search results that may help you out...

          http://modxcms.com/forums/index.php/topic,4014.0.html

          Cheers
            • 29902
            • 72 Posts
            You can use PHx for this inside templates and chunks.http://modx.com/extras/package/phx" target="_blank" rel="nofollow"> http://modx.com/extras/package/phx It can really help you on small things like making if-statements inside a template/chunk and create small snippets to modify template-variables directly. You really should learn how to use PHx smiley
              ...I believed it was Friday...
              • 32667
              • 38 Posts
              If you are using Revolution, you don't use phx, but input/output modifiers available in the core.

              See:

              http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+%28Output+Modifiers%29