We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41096
    • 7 Posts
    Greetings to everyone!

    Can anyone help me explain why this code is working as a snippet but not as a plugin?

    This little piece takes the results of a Wayfinder chunk and writes the Wayfinder output results to a new chunk.
    Having the menu "fixed" in a chunk speeds up the loading of my menu by about three times...

    When I am calling this as a snippet through a page, my menu gets updated and all is fine.

    BUT, I want this to execute automatically with "OnDocFormSave" through a plugin.
    When I try this, saving a resource goes on an endless "Saving..." loop.

    Any ideas?


    <?php
    $chunkWay = 'MegamenuWay';
    $output = $modx->getChunk($chunkWay);
    
     
    $chunkTxt = $modx->getObject('modChunk', array('name' => 'MegamenuTxt'));
        $chunkTxt->setContent($output);
        $chunkTxt->save();
        echo date('d.m.Y H:i:s');
    



    I am on Revo 2.2.6-pl (traditional)

    BR,
    GRE2608
      • 4172
      • 5,888 Posts
      in a OnDocFormSave-plugin you are in the mgr-context.
      wayfinder does only run correct, loaded on a resource in a web-context.

      whats your chunk-content of 'MegamenuWay'?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 41096
        • 7 Posts
        Its a mix of fixed links and Wayfinder calls...

        See below:

        <ul class="mega-menu" id="mega-menu-1">
        
        <li><a>Lowara</a>
        	<ul>
        		<li><a>[[#14.pagetitle]]</a>
        			[[Wayfinder? &startId=`14` &rowTpl=`LnkMenuProduct` &level=`1`]]
        		</li>
           			<li><a>[[#15.pagetitle]]</a>
        			[[Wayfinder? &startId=`15` &rowTpl=`LnkMenuProduct` &level=`1`]]
        		</li>
           			<li><a>[[#30.pagetitle]]</a>
        			[[Wayfinder? &startId=`30` &rowTpl=`LnkMenuProduct` &level=`1`]]
        		</li>
           			<li><a>[[#33.pagetitle]]</a>
        			[[Wayfinder? &startId=`33` &rowTpl=`LnkMenuProduct` &level=`1`]]
        		</li>
           			<li><a>[[#34.pagetitle]]</a>
        			[[Wayfinder? &startId=`34` &rowTpl=`LnkMenuProduct` &level=`1`]]
        		</li>
        	</ul>
        </li>
        
        <li><a>Flygt</a>
            <ul>
                <li><a>ΑΝΤΛΗΣΗ</a>
        			<ul>
                        <li><a href="http://www.flygt.com/en-us/Pumping/Products/Pages/Products.aspx" target="_blank">Προεπισκόπηση Προϊόντων<br>Άντλησης</a></li>
                        <li><a href="http://www.flygt.com/en-us/Pumping/Applications/Pages/Applications.aspx" target="_blank">Προεπισκόπηση Εφαρμογών<br>Άντλησης</a></li>
            			<li><a href="http://www.flygt.com/en-us/Pumping/Products/WetDry-well-pumps-submersible/Pages/Channel-impeller-pumps.aspx" target="_blank">Σειρά C<br>Υποβρύχιες Αντλίες Κλειστού Πτερυγίου</a></li>
                		<li><a href="http://www.flygt.com/en-us/Pumping/Products/WetDry-well-pumps-Submersible/Pages/Channel-impeller-pumps-stainless-steel.aspx" target="_blank">Ανοξείδωτες Ηλεκτραντλίες Καναλωτού Πτερυγίου</a></li>
                        <li><a href="http://www.flygt.com/en-us/Pumping/Products/WetDry-well-pumps-Submersible/Pages/Grinder-pumps.aspx" target="_blank">Ηλεκτραντλίες Με Κοπτήρα</a></li>
            			<li><a href="http://www.flygt.com/en-us/Pumping/Products/WetDry-well-pumps-Submersible/Pages/Chopper-pumps.aspx" target="_blank">Ηλεκτραντλίες Αυτοκαθαριζόμενου Πτερυγίου</a></li>
            			<li><a href="http://www.flygt.com/en-us/Pumping/Products/WetDry-well-pumps-Submersible/Pages/N-technology-pumps.aspx" target="_blank">Ηλεκτραντλίες Πτερυγίου N-Technology</a></li>
            			<li><a href="http://www.flygt.com/en-us/Pumping/Products/WetDry-well-pumps-Submersible/Pages/Vortex-impeller-pumps.aspx" target="_blank">Ηλεκτραντλίες Πτερυγίου Vortex</a></li>
            			<li><a href="http://www.flygt.com/en-us/Pumping/Products/WetDry-well-pumps-Submersible/Pages/Vortex-impeller-pumps-stainless-steel.aspx" target="_blank">Ανοξείδωτες Ηλεκτραντλίες Πτερυγίου Vortex</a></li>
                		<li><a href="http://www.flygt.com/en-us/Pumping/Products/Pump-stations/Pages/Pump-stations.aspx" target="_blank">Προκατασκευασμένοι Σταθμοί</a></li>
                        <li><a href="http://www.flygt.com/en-us/Pumping/Products/Portable-pumps-engine-driven/Pages/Portable-pumps-engine-driven.aspx" target="_blank">Μηχανοκίνητα Συγκροτήματα</a></li>
            </ul>
        		</li>
                <li><a>ΑΠΟΣΤΡΑΓΓΙΣΗ</a>
        			<ul>
            			<li><a href="http://www.flygt.com/en-us/Dewatering/Products/Pages/Products.aspx" target="_blank">Προεπισκόπηση Προϊόντων<br>Αποστράγγισης</a></li>
            			<li><a href="http://www.flygt.com/en-us/Dewatering/Applications/Pages/Applications.aspx" target="_blank">Προεπισκόπηση Εφαρμογών<br>Αποστράγγισης</a></li>
                    	<li><a href="http://www.flygt.com/en-us/Dewatering/Products/Drainage-pumps/Pages/Flygt-2600-series.aspx" target="_blank">Σειρά 2600</a></li>
                		<li><a href="http://www.flygt.com/en-us/Dewatering/Products/Drainage-pumps/Pages/Flygt-2000-series.aspx" target="_blank">Σειρά 2000</a></li>
                        <li><a href="http://www.flygt.com/en-us/Dewatering/Products/Drainage-pumps/Pages/Flygt-2700-series.aspx" target="_blank">Σειρά 2700</a></li>
                        <li><a href="http://www.flygt.com/en-us/Dewatering/Products/Slurry-pumps/Pages/5000-series.aspx" target="_blank">Σειρά 2700 - Υδαρούς</a></li>
            			<li><a href="http://www.flygt.com/en-us/Dewatering/Products/Drainage-pumps/Pages/Flygt-BIBO-2800-series.aspx" target="_blank">Σειρά BIBO</a></li>
            			<li><a href="http://www.flygt.com/en-us/Dewatering/Products/Drainage-pumps/Pages/Flygt-Ready.aspx" target="_blank">Σειρά Ready</a></li>
                        <li><a href="http://www.flygt.com/en-us/Dewatering/Products/Accessories/Pages/Product-range.aspx" target="_blank">Παρελκόμενα</a></li>
                    </ul>
        		</li>
                <li><a>ΑΝΑΔΕΥΣΗ</a>
        			<ul>
                        <li><a href="http://www.flygt.com/en-us/Mixing/Products/Pages/Products.aspx" target="_blank">Προεπισκόπηση Προϊόντων<br>Αναδευτήρων</a></li>
                        <li><a href="http://www.flygt.com/en-us/Mixing/Applications/Pages/Applications.aspx" target="_blank">Προεπισκόπηση Εφαρμογών<br>Αναδευτήρων</a></li>
                		<li><a href="http://www.flygt.com/en-us/Mixing/Products/Flygt-low-speed-mixers-4400-series/Pages/Flygt-low-speed-mixers-4400-series.aspx" target="_blank">Αναδευτήρες Low Speed</a></li>
                		<li><a href="http://www.flygt.com/en-us/Mixing/Products/flygt-mid-size-mixer-4500-series/Pages/default.aspx" target="_blank">Αναδευτήρες Mid Size</a></li>
                        <li><a href="http://www.flygt.com/en-us/Mixing/Products/Flygt-compact-mixers-4600-series/Pages/Flygt-compact-mixers-4600-series.aspx" target="_blank">Αναδευτήρες Compact</a></li>
            			<li><a href="http://www.flygt.com/en-us/Mixing/Products/Flygt-jet-mixers-4700-series/Pages/Flygt-jet-mixers-4700-series.aspx" target="_blank">Αναδευτήρες Jet Mixers</a></li>
            			<li><a href="http://www.flygt.com/en-us/Mixing/Products/Flygt-hydro-ejectors/Pages/Flygt-hydro-ejectors.aspx" target="_blank">Αναδευτήρες Hydro Ejectors</a></li>
            			<li><a href="http://www.flygt.com/en-us/Mixing/Products/Flygt-top-entry-agitators/Pages/Flygt-top-entry-agitators.aspx" target="_blank">Αναδευτήρες Top Entry</a></li>
                    </ul>
        		</li>
                <li><a>ΕΛΕΓΧΟΣ</a>
            		<ul>
                        <li><a href="http://www.flygt.com/en-us/Pumping/Products/Monitoring-and-Control-equipment/Pages/Monitoring-and-Control-equipment.aspx" target="_blank">Προϊόντα Ελέγχου & Παρακολούθησης</a></li>
                    </ul>
        		</li>    </ul>
        </li>
        
        
        <li><a>Sanitaire</a>
        	<ul>
            	<li><a>ΑΕΡΙΣΜΟΣ ΒΙΟΛΟΓΙΚΩΝ</a>
        			<ul>
        				<li><a href="http://www.xylemwatersolutions.com/scs/sanitaire/en-us/sanitaire-aeration-systems/coarse-bubble-aeration/Pages/default.aspx" target="_blank">Συστήματα Διάχυσης Χονδρής Φυσαλλίδας</a></li>
                    </ul>
        		</li>
            	<li><a>ΑΕΡΙΣΜΟΣ ΒΙΟΛΟΓΙΚΩΝ</a>
        			<ul>
            			<li><a href="http://www.xylemwatersolutions.com/scs/sanitaire/en-us/sanitaire-aeration-systems/fine-bubble-aeration/Pages/default.aspx" target="_blank">Συστήματα Διάχυσης Λεπτής Φυσαλλίδας</a></li>
                    </ul>
        		</li>
        	</ul>
        </li>
        
        <li><a>Wedeco</a>
            <ul>
        		<li><a>ΑΠΟΛΥΜΑΝΣΗ ΝΕΡΟΥ</a>
        			<ul>
        				<li><a href="http://www.wedeco.com/en/products/wedeco-uv-systems/aquada.html?langID=44" target="_blank">AQUADA<br>Συστήματα Απολύμανσης Υπεριώδους Ακτινοβολία<br>(UV)</a></li>
                    </ul>
        		</li>
        	</ul>
        </li>
        
        <li><a>Vogel</a>
            <ul>
            	<li><a>ΜΟΝΟΒΑΘΜΙΕΣ</a>
        			<ul>
        				<li><a href="http://www.vogelpumpen.com/single-stage-pumps_C1/" target="_blank">Μονοβάθμιες Ηλεκτραντλίες Επιφανείας</a></li>
                    </ul>
        		</li>
            	<li><a>ΠΟΛΥΒΑΘΜΙΕΣ</a>
        			<ul>
        				<li><a href="http://www.vogelpumpen.com/multistage-pumps_C2/" target="_blank">Πολυβάθμιες Ηλεκτραντλίες Επιφανείας</a></li>
                    </ul>
        		</li>
            	<li><a>ΚΥΚΛΟΦΟΡΗΤΕΣ</a>
        			<ul>
        				<li><a href="http://www.vogelpumpen.com/heating-air-conditioning-and-hot-water-circulation-pumps_C3/" target="_blank">Αντλίες Ανακυκλοφορίας Ζεστού/Κρύου</a></li>
                    </ul>
        		</li>
        	</ul>
        </li>
        
        <li><a>Seko</a>
        	<ul>
                <li><a>ΝΕΡΟ & ΒΙΟΜΗΧΑΝΙΑ</a>
        			<ul>
            			<li><a href="http://www.seko-group.com/page/standard/site.php?p=cm&o=vh&id=72" target="_blank">Ηλεκτρομαγνητικές Αντλίες</a></li>
            			<li><a href="http://www.seko-group.com/page/standard/site.php?p=cm&o=vh&id=80" target="_blank">Εμβολοφόρες Αντλίες</a></li>
            			<li><a href="http://www.seko-group.com/page/standard/site.php?p=cm&o=vh&id=83" target="_blank">Όργανα Μέτρησης</a></li>
            			<li><a href="http://www.seko-group.com/page/standard/site.php?p=cm&o=vh&id=82" target="_blank">Όργανα Πισίνας</a></li>
            			<li><a href="http://www.seko-group.com/page/standard/site.php?p=cm&o=vh&id=85" target="_blank">Παροχόμετρα</a></li>
                    </ul>
        		</li>
            	<li><a>ΚΑΘΑΡΙΜΟΣ & ΥΓΙΕΙΝΗ</a>
        			<ul>
        				<li><a href="http://www.seko-group.com/page/standard/site.php?p=cm&o=vh&id=73" target="_blank">Περισταλτικές Αντλίες</a></li>
            			<li><a href="http://www.seko-group.com/page/standard/site.php?p=cm&o=vh&id=87" target="_blank">Εξολπισμός Κουζίνας</a></li>
            			<li><a href="http://www.seko-group.com/page/standard/site.php?p=cm&o=vh&id=89" target="_blank">Εξοπλισμός Πλυντηρίων</a></li>
            			<li><a href="http://www.seko-group.com/page/standard/site.php?p=cm&o=vh&id=90" target="_blank">Εξοπλισμός Δαπέδων</a></li>
                    </ul>
        		</li>
        	</ul>
        </li>
        
        <li><a>GWS</a>
            <ul>
                <li><a>[[#156.pagetitle]]</a>
        			[[Wayfinder? &startId=`156` &rowTpl=`LnkMenuProduct` &level=`1`]]
        		</li>
           			<li><a>[[#157.pagetitle]]</a>
        			[[Wayfinder? &startId=`157` &rowTpl=`LnkMenuProduct` &level=`1`]]
        		</li>
           			<li><a>[[#158.pagetitle]]</a>
        			[[Wayfinder? &startId=`158` &rowTpl=`LnkMenuProduct` &level=`1`]]
        		</li>
           			<li><a>[[#159.pagetitle]]</a>
        			[[Wayfinder? &startId=`159` &rowTpl=`LnkMenuProduct` &level=`1`]]
        		</li>
        	</ul>
        </li>
        
        <li><a>SFA Group</a>
            <ul>
                <li><a>ΜΙΚΡΑ WC</a>
            		<ul>
        				<li><a href="http://www.saniflo.com/homeowners/sfa-product-line/adaptable-grinders-and-compact-grinders-for-toilets/" target="_blank">Μικρά Συστήματα & Λεκάνες Με Αντλία</a></li>
                    </ul>
        		</li>
            	<li><a>ΚΑΝΟΝΙΚΑ ΜΠΑΝΙΑ</a>
        			<ul>
        				<li><a href="http://www.saniflo.com/homeowners/sfa-product-line/adaptable-grinders-pumps-and-compact-grinders-for-bathrooms/" target="_blank">Συστήματα Για Ένα Πλήρες Μπάνιο</a></li>
                    </ul>
        		</li>
            	<li><a>ΚΟΥΖΙΝΑ / ΠΛΥΣΤΑΡΙΟ</a>
        			<ul>
        				<li><a href="http://www.saniflo.com/homeowners/sfa-product-line/pumps-for-kitchen-and-laundry-room/" target="_blank">Συστήματα Για Απόνερα Χωρίς Λύματα Τουαλέτας</a></li>
                    </ul>
        		</li>
            	<li><a>ΜΙΚΡΕΣ ΚΑΤΟΙΚΙΕΣ</a>
        			<ul>
        				<li><a href="http://www.saniflo.com/homeowners/sfa-product-line/adaptable-grinders-and-lift-stations-for-small-spaces-and-commercial-buildings/" target="_blank">Πλήρεις Σταθμοί Άντλησης</a></li>
                    </ul>
        		</li>
        	</ul>
        </li>
        
        <li><a href="[[~151]]">B&F</a>
        </li>
        
        
        <li><a>ΥΔΑΤΩΡ A.E.</a>
        		<ul>
                <li><a>Διαδίκτυο</a>
                    <ul>
            			<li><a href="http://www.idator.net/" target="_blank">Blog</a></li>
                    </ul>
                    <ul>
            			<li><a href="https://twitter.com/idatorsa/" target="_blank">Twitter</a></li>
                    </ul>
                    <ul>
                		<li><a href="https://el-gr.facebook.com/idatorsa/" target="_blank">Facebook</a></li>
                    </ul>
                    <ul>
                		<li><a href="http://eepurl.com/seKHf" target="_blank">Newsletter</a></li>
                    </ul>
                </li>
            		<li><a>[[#144.pagetitle]]</a>
        				[[Wayfinder? &startId=`144` &rowTpl=`LnkMenuSimple` &cacheResults=`1` &level=`1`]]
        			</li>
            		<li><a>[[#145.pagetitle]]</a>
        				[[Wayfinder? &startId=`145` &rowTpl=`LnkMenuSimple` &cacheResults=`1` &level=`1`]]
        			</li>
                	<li><a>[[#148.pagetitle]]</a>
        				[[Wayfinder? &startId=`148` &rowTpl=`LnkMenuSimple` &cacheResults=`1` &level=`1`]]
        			</li>
                	<li><a>Links</a>
                	<ul>
        				<li><a href="http://www.lowara.com/index2.php" target="_blank">Lowara</a></li>
                    </ul>
                	<ul>
        				<li><a href="http://www.flygt.com/" target="_blank">Flygt</a></li>
                    </ul>
                    <ul>
        				<li><a href="http://www.sanitaire.com/" target="_blank">Sanitaire</a></li>
                    </ul>
                    <ul>
        				<li><a href="http://www.wedeco.com/" target="_blank">Wedeco</a></li>
                    </ul>
                    <ul>
        				<li><a href="http://www.vogelpumpen.com/" target="_blank">Vogel</a></li>
                    </ul>
                    <ul>
            			<li><a href="http://www.seko.com/" target="_blank">Seko</a></li>
                    </ul>
                    <ul>
            			<li><a href="http://www.globalwatersolutions.com/" target="_blank">GWS</a></li>
                    </ul>
                    <ul>
            			<li><a href="http://www.saniflo.com/" target="_blank">SFA Group</a></li>
                    </ul>
        			</li>
        		</ul>
        	</li>
        
        </ul>
        
        


        You can see the menu at work here: www.idator.eu


        Thanks!
          • 4172
          • 5,888 Posts
          not sure if this will work,
          but you could try to put this whole thing onto a special resource with an empty template
          and let it render by renderResources http://rtfm.modx.com/display/ADDON/renderResources
          rendering just this single Resource with this menue in it, in your plugin.

          btw.: It would also be possible to build the whole tree with one wayfinder-call and some special tpl-chunks, if you would build your Resource-tree like your menue.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 3749
            • 24,544 Posts
            Try it without this line:

            echo date('d.m.Y H:i:s');
              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
              • 41096
              • 7 Posts
              Hello guys!

              The last line, "echo date", was added following all the tests just to verify that the snippet is called every time and I don't get cached results. The initial code did not include it and still it didn't work.

              Bruno I'll try your first solution an I'll let you know.

              At the moment, since changes to the menu are minimal I have added the snippet at the end of a rarely used resource "Company History" and I visit it every time I need to update it.

              Thank you both and I'll keep you updated if I manage to find a workaround.

                • 41096
                • 7 Posts
                Hello guys!

                I tried what Bruno suggested without any luck.
                Resource 164 has a blank template and renders the full menu when run individually.
                When I try it inside a plugin it never finishes execution.

                Have a look at the code below and let me know if you see anything...

                <?php
                $output = $modx->runSnippet('renderResources', array('resources' =>'164'));
                 
                $chunkTxt = $modx->getObject('modChunk', array('name' => 'ZooMegamenuTxt'));
                $chunkTxt->setContent($output);
                $chunkTxt->save();
                
                $modx->cacheManager->clearCache();
                


                BR,
                GRE2608
                  • 3749
                  • 24,544 Posts
                  I think you may need this:

                  array('parents=`-1`, 'resources' =>'164')
                    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