We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4038
    • 21 Posts
    Hi guys,
    I am currently building a new site with modX.
    Before, I’ve been using the site without modX and it worked quite well.

    I’m using a Javascript menu (fold-out. http://www.foerderverein-drucktechnik-duesseldorf.de"" target="_blank" rel="nofollow">You can see it in action here.)
    There’s also a PHP-call to determine which category is open and then it can stay open after reloading the site.

    I know that I can’t execute PHP in the templates, so I created 2 snippets.
    Snippet 1:
    <?php
    $x = "show";
      switch($_GET['menue'])
        {
            case 1:     $menue1 = $x; break;
            case 2:     $menue2 = $x; break;
            case 3:     $menue3 = $x; break;
            case 4:     $menue4 = $x; break;
            case 5:     $menue5 = $x; break;
        }
    ?>


    Snippet 2:
    <?php
    PHP echo $menue2;
    ?>


    Code of the menu:
    <div class="nav_wrapper"> 
                                        <ul id="menu">
                              <li class="show" onclick="mShow(this);">Verein
                                 [!Wayfinder? &startId=`2` &level='0'!]
                              </li>
                            
                              <li class="[!menue2!]" onclick="mShow(this);">Gautschen
                                [!Wayfinder? &startId=`5` &level='0'!] 
                              </li>
          </div>
    


    I’m calling the first snippet in the <head> area.

    Problem is, that it doesn’t work. The variable doesn’t get echoed.
      • 25483
      • 741 Posts
      try this:

      <?php
      return $menue2;
      ?>
      
        with regards,

        Ronald Lokers
        'Front-end developer' @ h2o Media

        • 4038
        • 21 Posts
        Thanks, but it doesn’t change anything...
          • 25483
          • 741 Posts
          uhm wait... I am not sure if you can pass variables between snippets! Maybe you have to merge it to just 1 snippet?
            with regards,

            Ronald Lokers
            'Front-end developer' @ h2o Media

            • 7231
            • 4,205 Posts
            I don’t understand the code. You are setting the ’show’ class via the URL string using GET? But the way you are doing it you would need to define each var individually. Are all the manu items on the same page so that you need to set all the vars at the same time? If so use placeholders:
            <?php
            $x = "show";
              switch($_GET['menue'])
                {
                    case 1:     $modx->setPlaceholder(menue1, $x); break;
                    case 2:     $modx->setPlaceholder(menue2, $x); break;
                    case 3:     $modx->setPlaceholder(menue3, $x); break;
                    case 4:     $modx->setPlaceholder(menue4, $x); break;
                    case 5:     $modx->setPlaceholder(menue5, $x); break;
                }
            ?>


            Then in the code use the placeholder like this:
            <li class="[+menue2+]" onclick="mShow(this);">Gautschen
            [!Wayfinder? &startId=`5` &level='0'!] 
            </li>


            If show is the only class you can edit it to include the class="" in the placeholder to avoid having empty class definitions:
            $x = 'class="show"';
            then in the html use:
            <li [+menue2+] onclick="mShow(this);">Gautschen
            .

            There are several other ways to do this as well, but this should help wink

              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 4038
              • 21 Posts
              Thank you very much. This works flawless!
              Now my next problem is the following.

              For the script to work I need to pass
              &menue=2

              after the URL.

              For example:
              domain.com/modx/index.php?id=9&menue=2


              How do I do this dynamically in ModX?
                • 7231
                • 4,205 Posts
                What is the trigger that defines the menu var? What i mean is do you want the menu to work in a particular section of the site or will it be more random and needs to be tied to a link event? I ask because if you want the documents parent (section) to be the trigger we can use the document model and define this without using a URL value (which can be unsightly).

                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 4038
                  • 21 Posts
                  You see I have the 5 categorys on the left?
                  Verein
                  Gautschen
                  Sportveranstaltungen
                  Absolvententreffen
                  Studienfahrt

                  They are numbered from top to bottom. For example, Gautschen is number 2.

                  Now depending on what categorie you chose a site from, the corresponding trigger has to be passed. For example &menue=2 for "Gautschen". Or &menue=3 for "Sportveranstaltungen" and so on.

                  To be honest, I don’t mind whether the trigger is sightly or not, most important is that it works. But I’d love to see a solution that is unsightly.
                    • 7231
                    • 4,205 Posts
                    Quote from: Breen at Apr 16, 2009, 05:21 PM

                    You see I have the 5 categorys on the left?
                    Verein
                    Gautschen
                    Sportveranstaltungen
                    Absolvententreffen
                    Studienfahrt

                    Do these correspond to the MODx document tree? If so we can use the id or parent (or even ultimate parent).

                    -Parent Doc (1)
                    ----Verein (2)
                    ----Gautschen (7)
                    ----Sportveranstaltungen (13)
                    ----Absolvententreffen (21)
                    ----Studienfahrt (33)

                    If this is the setup then we can use the parent or doc id as the trigger for the snippet.

                    If that is not the case, to get the trigger in the link simply add &menue=1 to the links
                    <a href="[~12~]&menue=1">link</a>

                      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                      Something is happening here, but you don&#39;t know what it is.
                      Do you, Mr. Jones? - [bob dylan]
                      • 4038
                      • 21 Posts
                      I have the categories as you said but the words "Verein", "Gautschen" and so on are hardcoded because I don’t want redirection to another site on click.
                      So I am not shure if it would work what you have said.

                      But the second solution sounds promising. I’m just not sure where I am supposed to tipe it in. I already tried to do it via user friendly URLs, but it doesn’t work...