We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36909
    • 15 Posts
    Hi all,

    I'm wondering if it is possible to create a resource that, when accessed, runs a snippet in order to decide where to direct the user to. So, essentially, a weblink, but with the ability to have its content parsed.

    The site I am working on is a portfolio, where my client has a number of projects displayed. Each project is a resource. The client would like the "Gallery" link in the primary navigation to take the user to the most recently added project.

    I had thought the solution was to create a weblink and stick a snippet call into the content, but of course, weblink content isn't actually parsed, so that won't work. Next I tried to do the same with a static resource since, according to the page in the manual, "you can specify custom paths to set as System Settings, or use Snippets to dynamically find the path," which is exactly what I want to do. But that doesn't appear to be working either. I get a blank, white page. Here is the snippet call I am using:

    [[getResources? &limit=`1` &parents=`3` &hideContainers=`1` &sortby=`publishedon` &sortdir=`DESC` &tpl=`Gallery Link Output`]]


    I've tried having the template return the ID, a link to the ID and the alias of the project resource. No dice.

    I would consider merely calling the above snippet in the navigation, but I'd like to be able to use Wayfinder and the content of this page might eventually change (the client may decide to have a landing gallery page with unique content on it). I would consider writing a custom snippet that programmatically redirects, but I feel like there is a better, simpler way to do this. Can I add a content disposition that contains a 302 redirect, perhaps?

    What am I doing wrong? Am I going about this the wrong way? Is there a better way?

    Thanks in advance.
      • 3749
      • 24,544 Posts
      The getResources tag should do it. I assume that the gallery pages are children of resource 3?

      What happens when you take out the &hideContainers property?

      Make sure the pages you want to link to are published and not hidden from menus.

      If you want to just redirect the user, rather than showing a link, a custom snippet if probably the most efficient. Something like this (untested):

      <?php
      $c = $modx->newQuery('modResource');
      $c->limit(1);
      $c->sortBy('publishedon', 'DESC');
      $c->where(array(
         'published' => '1',
         'deleted' => '0',
         'parent' => '3',
         'isfolder' => '0',
         'hidemenu' => '0',
      ));
         
      $docs = $modx->getCollection('modResource', $c);
      
      if (empty($docs)) {
       return 'No Document Found';
      }
      $docId = $docs[0]->get('id');
      
      $modx->sendRedirect($modx->makeUrl($docId, "", "", "full"));
      



      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODx info for everyone: http://bobsguides.com/MODx.html
        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
        • 36909
        • 15 Posts
        Hi Bob,

        Thanks for your reply.

        Yes, the gallery pages are children of resource 3. The hideContainers property is there because the projects are organized in container folders that aren't themselves projects, so it was conscious decision to not include them. I tried removing the property anyway (I think I know where you're going with that suggestion), and got the same, blank, white page. Everything is published and visible. I feel like the getResources call I am using is not returning the proper data for the static resource to interpret or something.

        Perhaps I will just go with the custom snippet as you suggest.

        Thanks again.
          • 3749
          • 24,544 Posts
          Is there some reason you don't want to do it with a regular resource/document?


          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODx info for everyone: http://bobsguides.com/MODx.html.
            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