We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16430
    • 217 Posts
    Quote from: BobRay at Mar 18, 2013, 01:15 PM
    Is this Evolution or Revolution?

    In Evolution, everything with children is automatically a container. In Revolution being a container is manual, you set the Container status by checking a checkbox, which sets the isFolder field whether the Resource has children or not. In Revo, you may be able to set the container status manually to get what you want.

    I think Wayfinder uses hasChildren() for naviagtion but checks the isFolder field for setting the container classes. I could be wrong.

    You could write a plugin tied to OnDocFormSave that would set the isFolder field based on the presence or absence of children so Revo would work the same as Evo.
    Its Revo. There is no problem to manualy set resource as a container but using Wayfinder to show only those folder that has children on it lowest level.
    For example:


    -Folder (show)
    --SubFolder (show)
    ---Child
    ---Child
    --SubFolder (hide)
    --SubFolder (hide)
    -Folder (hide)
    --SubFolder (hide)
      • 3749
      • 24,544 Posts
      If you're going to be designating them manually, why not just check the "Hide from Menus" box?
        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
        • 16430
        • 217 Posts
        Quote from: BobRay at Mar 18, 2013, 03:53 PM
        If you're going to be designating them manually, why not just check the "Hide from Menus" box?
        Lets imagine that I have catalogue of goods. I will create multiple categories and subcategories, and logged user will create content via front-end. They will fill those categories gradually. So point is not to have any empty categories visible...
          • 3749
          • 24,544 Posts
          Right, but if you check the "Hide from Menus" checkbox on the empty folders, they won't show in the menu.

          If you want to automate things, I think this plugin attached to OnDocFormSave would do it:


          <?php
          $children = $modx->getMany('Children');
          $setting = empty ($children)? true : false;
          $resource->set('hidemenu', $setting);
          $resource->save();
          


          You could also set isFolder instead, but this would be more straightforward, since it's exactly what you want to do (if I'm understanding you).
            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
            • 16430
            • 217 Posts
            I dont think you understand me.
            To be more specific... In front end user will create new resource (using formit2resource) and also can choose specific category for resource to be stored in (premade folder). So in menu there could be around 20 folders but only once a new child is added then the folder become visible. Until then, all empty folders are hidden.

            Another problem could be the structure. => Folder ->Subfolders->Child
            If I understand correctly Subfolder is already Child of Folder, no? But this might be solved by setting the folder resource as a folder or use an empty template.
              • 3749
              • 24,544 Posts
              Quote from: kudykam at Mar 19, 2013, 02:49 AM
              I dont think you understand me.

              It wouldn't be the first time. wink


              I think I get it now. It sounds like you want something like this (with hidemenu checked on all folders).


              <?php
              
              if ($resource->get('parent')) { // only act on non-root docs
                  $parentObj = $resource->getOne('Parent');
                  /* turn off parent's hidemenu field if set */
                  if ($parentObj->get('hidemenu')) {
                      $parentObj->set('hidemenu', 0);
                      $parentObj->save();
                  }
              }



              Note that this will not set hidemenu to true for parents when you delete all their children. To do that you'd need more code and you'd need to attach the plugin to a resource delete event as well. [ed. note: BobRay last edited this post 13 years, 7 months ago.]
                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
                • 16430
                • 217 Posts
                when/how to call this snippet?
                  • 3749
                  • 24,544 Posts
                  It's not a snippet. It would be a plugin attached to the OnDocFormSave event.

                    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
                    • 16430
                    • 217 Posts
                    Yeah, that what I thought, but it does nothing....
                    I set directory and its subdirectory to hidden...
                    Then create resource in subdirectory, but both directories are still hidden...
                      • 3749
                      • 24,544 Posts
                      Sorry, typo in the code. Try the new version above.
                        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