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

    I'm new to modx and I'm trying to write a snippet, which calls a chunk with a parameter, depending on which site the user actually is.

    I have four resources container with the pagetitles home, user, jobs and system! They are accessible under https://localhost/modx/home/ etc.

    And now i like to have a quickstart-div, with a different content, depending on the resources container. When a user opens https://localhost/modx/home/ the input-field in the quickstart div should be named "homesearch" and so on with the other resources.

    My snippet:
    $site = '[[*pagetitle]]';
    $site = @trim($site);
    
    switch ($site) 
    {
       case 'home':
           $output = $modx->getChunk('ch_quickstart', array('name' => 'homesearch'));
           break;
       case 'jobs':
           $output = $modx->getChunk('ch_quickstart', array('name' => 'jobid'));
           break;
       case 'user':
           $output = $modx->getChunk('ch_quickstart', array('name' => 'usernr'));
           break;
       case 'system':
           $output = $modx->getChunk('ch_quickstart', array('name' => 'sysid'));
           break;
       default:
           $output = "";
    }
    return $output;
    


    und a chunk, named "ch_quickstart":
    <div id="quickstart">Quickstart: <input type="text" name="[[+name]]" /></div>


    But when i call the snippet in the template, the problem is, that the switch doesn't work! It always returns nothing. And i also tried back-tics but they also don't work...
    Anybody got an idea, what's wrong? Or is this simply the wrong way, to realize such a feature in modx?

    Thank you in advance!
      • 33337
      • 3,975 Posts
      Not a direct answer to your question, but I tried your snippet with no luck. Though I can suggest another way of doing it, please see the following:

      1. install Switch snippet from the repo: http://www.modx.com/extras/package/switch

      [[!switch?
          &get=`[[*pagetitle:lcase]]`
          &c1=`home` &do1=`[[$ch_quickstart? &name=`homesearch`]]`
          &c2=`jobs` &do2=`[[$ch_quickstart? &name=`jobid`]]`
          &default=``
        ]]


      Hope it helps and save some time.
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 28215
        • 4,149 Posts
        Erm, instead of doing:

        $site = '[[*pagetitle]]';
        


        Do:

        $site = $modx->resource->get('pagetitle');
        
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 37004
          • 2 Posts
          Thank you very much! Now it works perfectly smiley