We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27708 MODX Staff
    • 2,502 Posts
    I have a 2nd level menu created in DropMenu in 0.9.2.2 and I want to be able to display it in the parent and sibling documents only. I don’t want to necessarily do it with multiple templates.

    I would think that I could create either a snippet or a TV (don’t really understand these yet) that offers a conditional like:

    if 
    
    document.parent == 'foo'
    
    elseif 
    
    document == 'foo';
    
    echo 'menu.for.foo';
    
    else echo ' ';
     
    


    I know the above syntax is not entirely correct and would obviously correct the php when implementing.

    I just wonder if this is doable and if I can use MODx’s built in variables within or do I have to use the function calls to do this? Is there a better way to do this with a TV or am I off the mark here?
      Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
      • 11975
      • 2,542 Posts
      Hi,

      You could try to do it using a TV

      1/Create a chunk (named myMenu for instance) in wich you paste the dropMenu call.

      2/Create a Tv named displayMenu
      TV type=>radio
      In options value=>None==||myMenu=={{myMenu}}
      In default value=>@INHERIT
      Attach the Tv to your template.

      3/Insert [* displayMenu*] in your template

      4/ Edit the parent document and set displayMenu value to myMenu

      That should work.
      You could also have alook to PHX plugins which allows conditionnal syntax.

      :-)
        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
        • 27708 MODX Staff
        • 2,502 Posts
        heliotrope,

        thanks for the suggestion but I didn’t get it to work. I am not really clear on the use of TVs yet as I haven’t seen enough simple examples yet. I still have a lot to learn using MODx and am not able to debug any mistakes I may have made.

        I know it is not the best scenario but I was able to get it to work in the following way (the way I had figured in the first place):

        I created a Chunk called homes_menu and then I created a Snippet called show_homes_menu with the following code:

        <?php
        if ($modx->documentObject['id'] == '2'|$modx->documentObject['parent'] == '2')
        {echo '{{homes_menu}}';}
        else {echo '';}
        ?>
        


        I then inserted [[show_homes_menu]] in my place_subcontent chunk.

        Part of my requirement was that I wanted to be able to have the menu in a common chunk instead of sticking it into the document or the document parent.

        There may have been an easier way to do this and I also expect that I could take this one further and check the current id and if there was a menu associated with it, display it. It could be done with an array or some such.

          Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
          • 7455
          • 2,204 Posts
          SectionRoots would do the trick I think or GetChunkByUPID or UltimateParent itself.
            follow me on twitter: @dimmy01
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Try this, it’s a lot more "MODx" and a lot more fun:
            <?php
            if ($modx->documentObject['id'] == $modx->config['site_start'] || $modx->documentObject['parent'] == $modx->config['site_start']) {
              return $modx->runSnippet('DropMenu',array('opt1'=>'val1','opt2'=>'val2','opt3'=>'val3'));
            }
            ?>
            
              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
              • 27708 MODX Staff
              • 2,502 Posts
              sottwell,

              I see that that should make more sense. I don’t see where the variable ’site_start’ came from. Is this somewhere in the documentation? I found the other information I was looking for here: http://modxcms.com/document-tvs.html but don’t see it there.

              All the best,

              Jay
                Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                The $modx->config array contains all of the information in the site_configuration table in the database, plus a bit more. This includes site_start and site_name, which are commonly used. Outside of snippet code, these are [(site_name)] and [(site_start)].

                In one of your snippets, put this code:
                echo "<pre>";
                print_r($modx->config);
                echo "</pre>";
                exit();
                

                and you’ll get a pageful. I saved that to a text file and keep it handy for reference.
                  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