We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Quote from: ad2003 at Apr 03, 2013, 06:31 AM


    $alias = $modx->resource->get('alias');
    if ($alias == 'contact' || $alias == 'contact'){
    return $modx->getChunk('demo');
    }
    return '';


    Note the change to the last line. Without that you may get the number 1 mysteriously showing up on your pages. 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
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I think the original sample code that was copied had
      if ($alias == 'index' || $alias == 'index.html'){

      to cover cases where the default suffix is blank, and for various reasons the suffix .html is hard-coded into the alias.

      The || in PHP means "or", so if you only want to check for one alias value, just eliminate that part of the code.
      if ($alias == 'contact'){

      Note the double ==

      A common newbie PHP programming error is to use one = which is the assignment operator "make $thisvariable contain thisvalue.". The == is the comparison operator "does $thisvariable contain thisvalue?", and === is an exact comparison operator "is $thisvariable the exact same thing as thisvalue?", which is subtly different than == especially when checking for true/false values.
        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
        Well then, the addition of the .html makes sense. So, since MODX producing aliases with the full file designation (in some instances), is just the alias that is generated (or placed) in the alias field good enough for a snippet in MODX?
          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
          If you are using it to identify a resource, perhaps. There are cases where aliases are duplicated, in which case it may or may not be significant. Personally, when a specific resource needs to be identified, I use the resource ID.

          The "alias" field is what you edit for a resource. When using it to generate a URL, MODx will append the appropriate suffix as specified in System -> Content Types. For example, if a resource has the type HTML (the default) then MODx will add .html to the alias. If it's of the type CSS then MODx will add .css to the alias.

          Likewise when the server invokes MODx with the rewritten URL of index.php?q=alias.suffix, MODx will parse the URL to get the alias.html part, and will check for what resource has that alias. MODx doesn't have to hit the database for this, since it keeps a map of alias->ID cached somewhere, and (I think) this array is automatically loaded on every page request.
            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
            so essentially, within MODX... all that is needed is the alias?
              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
              Yes. Just keep in mind that it may not be a 100% reliable identifier of any single resource. Only the resource ID will do that.
                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