We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42101
    • 125 Posts
    Hi!

    I'am trying to load a snippet on a specific pageid with a code example from http://creativedev.in/2012/09/conditional-chunk-in-modx/:

    if ($alias == 'contact' || $alias == 'index.html'){
    echo $chunk = $modx->getChunk('demo');
    }


    the redirect page is alias:contact - I am not sure what to write instead of index.html...

    It doesn't work. My page url looks like this:

    http://mywebpage.com/index.php?id=5&#contact


    I am using formit with a redirect to a "thanks" page. I want to have a field like "your email was sent successfully" after a visitor pressed the botton. At the moment I am using a modified getResources call to exclude the "thanks" area. But this is not as dynamical as it should be...

    thanks!

    AD
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      For one thing, I would suspect that the second alias should be "index", not "index.html". MODx appends .html to the alias, so the alias itself is without the .html part.
        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
        • 42101
        • 125 Posts
        Quote from: sottwell at Apr 02, 2013, 08:59 PM
        For one thing, I would suspect that the second alias should be "index", not "index.html". MODx appends .html to the alias, so the alias itself is without the .html part.

        thanks for the reply - but no...not the reason it's not working. I was wondering about the html ending too.
        greetings,

        AD
          • 4172
          • 5,888 Posts
          to see the alias of a page:

          [[*alias]]
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            That code doesn't make a lot of sense; where is the variable $alias defined?
            Try
            $alias = $modx->resource->get('alias');
            if ($alias == 'contact' || $alias == 'index'){
            return $modx->getChunk('demo');
            }
            return;
            


            Snippets should never "print" or "echo", they should always "return" whether they return any output or not.
              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
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              You could also do this with an output modifier:
              [[*alias:is=`contact`:then=`[[$demo]]`]]
                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
                ^^^^^ try that. So much simpler. :~}
                  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
                  Well, its simplicity comes at a price, it only works for one alias. If you want to check for multiple aliases, then you need the snippet.
                    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
                    • 42101
                    • 125 Posts
                    Quote from: sottwell at Apr 03, 2013, 01:03 AM


                    Snippets should never "print" or "echo", they should always "return" whether they return any output or not.

                    good point. thank you all! Works now with the snippet.

                    I changed the "index" also into the alias:

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


                    Very nice to know how to use conditional tags...learning every day a bit more - great.

                    AD
                    [ed. note: ad2003 last edited this post 13 years, 6 months ago.]
                      • 10208 ☆ A M B ☆
                      • 1,780 Posts
                      Well, I imagine it's cuz I don't know php well that I misunderstand... But the || followed with the same alias, so it seemed like only one condition is applying anyway. heh... I'm sure I'm missing something important.
                        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