We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16430
    • 217 Posts
    Hi,
    I need to create filter that will show only todays "lunch menu" from five TVs (mon, tue, wed,..)
    I have this call on page:
    [[!getResources?  &resources=`24`  &includeTVs=`1` &tpl=`daily-menu` ]]


    template (daily-menu):
    [[+tv.menu-Mon:istoday=`Mon`:then=`<h4>Monday:</h4><p> [[+tv.menu-Mon]]</p> `]]
    [[+tv.menu-Tue:istoday=`Tue`:then=`<h4>Tuesday:</h4><p> [[+tv.menu-Tue]]</p> `]]
    ...
    


    Snippet (istoday):
    <?php
    $today=date("D");
    if ($today == $options) return true;
    else  return false;


    Well this doesnt work, I cannot figure out why...
      • 3749
      • 24,544 Posts
      kudykam, that's a really slow way to do it. Conditional operators are slow to begin with, and arsine so many cases makes them way slower. Then putting all that inside getResources slows things down further. Also, using chunks soups be mere efficient than resource for the menus.

      I'm on my phone so forgive the formatting, but I'd suggest just using a snippet to pull in the correct menu chunk. If you name the chunks mon, tue, etc., you can do it with this line alone:

      return $modx-> getChunk(date('D'));
      
        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 am using your snippet to pickup a chunk (called: Mon, Tue,...) that contains:
        Mon:
        <h4>Monday:</h4><p> [[+tv.menu-Mon]]</p>


        But on page snippet shows only:
        <h4>Monday:</h4><p></p>


        I should also mention that I am grabbing this tv from different page, thats why I have to use getresource like:
        [[!getResources?  &resources=`24`  &tpl=`menu-rotator` &includeTVs=`1`  ]]

        and in this "menu-rotator" template is your snippet that gets menu form chunks... [ed. note: kudykam last edited this post 12 years, 6 months ago.]
          • 3749
          • 24,544 Posts
          You could use another snippet to get the TV value and then pull the right menu, but why not just put the menu in the chunk?
            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
            What another snippet?
            ...beacuse menu will change every week and it has to have user firendly input (for customer)
              • 3749
              • 24,544 Posts
              OK, how about this:

              [[!GetMenu]]


              <?php
              /*GetMenu snippet */
              
              $resource = $modx->getObject('modResource', array ('pagetitle'=>date('D'));
              
              if ($resource) {
                  return $resource->getContent();
              } else {
                  return 'Could not find resource: ' . date('D');
              }
              


              The resources don't have to be published or shown in menus, and you can get them by alias, if you prefer, by changing 'pagetitle' to 'alias'.
                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
                Pardon my ignorance but how am I suppose to use this snippet?
                  • 3749
                  • 24,544 Posts
                  Create a snippet with that name and paste the code into it.

                  Put the snippet tag where you want the menu to appear.

                  I think you already have the resources (Mon, Tue, etc.).
                    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
                    The page returns:
                    HTTP 500 (Internal Server Error)
                    Which is no surprise for me, because I see in your code some pagetitle and date, which makes no sense to me. How could this return chunks (named Mon, Tue, ...)?

                    Sample of chunk mon:
                    <strong>Polévka:</strong> [[*menu-po0]] - [[*cena-0]],- Kč<br/>
                    <strong>Menu 1:</strong> [[*menu-po1]] - [[*cena-1]],- Kč<br/>
                      <strong>Menu 2:</strong> [[*menu-po2]] - [[*cena-2]],- Kč</p>


                    How this script will recognize from which page to take this TV`s?
                      • 3749
                      • 24,544 Posts
                      Quote from: BobRay at Nov 13, 2011, 04:02 PM

                      I think you already have the *resources* (Mon, Tue, etc.).

                      You told me you wanted the menu in resources, not chunks. That's why I modified the code to retrieve resource content.

                        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