We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36516
    • 179 Posts
    Hello

    I've used getResources to show article summaries in three columns, using &tplFirst and &tplLast in conjunction with &tpl_nN to achieve the <div>s I need between every three items.

    The first issue I had was rather convenient because it revealed this potential issue: I hadn't upgraded to the latest version of getResources so mine didn't actually support &tpl_nN at all. As a result the output code exhibited &tplFirst and &tplLast and nothing between.

    Having upgraded to the latest version of getResources (1.4.2 from 1.3.0) &tpl_nN began to work, but it seems the my n3 template overrides &tplLast such that if the last item on the page happens also to be the 3rd [in the row] getResources prioritises the &tpl_nN template instead of that of &tplLast.

    Conventional wisdom would suggest, surely, that &tplLast should take precedence, though I can see an argument for providing the option. However at present I'm unsure how to solve this problem. I'm surprised &tpl_nN took so long to be implemented in getResources, as it seems so fundamental, but is it possible this behaviour is unintended?

    Thanks
      • 36516
      • 179 Posts
      This is some fairly basic functionality, no? Has nobody else any experience with tpl_nN? The inability to enforce a 'Last' template to override the n'th is rather a flaw, presuming nobody has a workaround.

      I'd appreciate any suggestions, but in addition if anyone can tell me how I can get in touch with the developer of getResources directly it might pay to get a direct answer.

      Thanks again.
        • 22303 MODX Staff
        • 10,725 Posts
        All you need do is enter a ticket for your issue at https://github.com/opengeek/getResources/issues and it will be resolved as soon as the author (me in this case) or anyone willing to contribute a fix has provided one.
          • 36516
          • 179 Posts
          Ah, thanks very much! And you're the author? You don't happen to know what I'm talking about, do you? I'm happy to proceed with the ticket submission, unless you can already tell me that it's by design. But if that was the case I expect you'd have already told me... smiley
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: davidsmith at Mar 01, 2012, 11:25 AM
            Ah, thanks very much! And you're the author? You don't happen to know what I'm talking about, do you? I'm happy to proceed with the ticket submission, unless you can already tell me that it's by design. But if that was the case I expect you'd have already told me... smiley
            I am, and I do know what you are talking about. It is not by design, just an oversight in it. Thanks for reporting the issue and I'll get it resolved asap.
              • 38055
              • 2 Posts
              Hi guys,

              I'm developing a site in modx and I stumbled upon this issue as well.

              I have implemented a fix, it's rather crude but doesn't really change any of the logic hugely. I thought I'd post it here just in case anybody has a similar issue. I've learnt so much from these foums just thought I'd give something back.

              On line 444 add:
              $isOdd = false;
              if ($idx > 1 && empty($resourceTpl)) {
              


              On line 450 add the following right after the template parse call:
              $isOdd = true;
              


              On line 461 add the following new condition into the if statement:
              if ($idx == $last && ($isOdd || empty($resourceTpl)) && !empty($tplLast)) {
                      $resourceTpl = parseTpl($tplLast, $properties);
              }
              


              Here's the whole lot as it should look:
              ...
                  $isOdd = false;
                  if ($idx > 1 && empty($resourceTpl)) {
                      $divisors = getDivisors($idx);
                      if (!empty($divisors)) {
                          foreach ($divisors as $divisor) {
                              $tplnth = 'tpl_n' . $divisor;
                              if (!empty($$tplnth)) {
                                  $resourceTpl = parseTpl($$tplnth, $properties);
                                  $isOdd = true;
                                  if (!empty($resourceTpl)) {
                                      break;
                                  }
                              }
                          }
                      }
                  }
                  if ($idx == $first && empty($resourceTpl) && !empty($tplFirst)) {
                      $resourceTpl = parseTpl($tplFirst, $properties);
                  }
                  if ($idx == $last && ($isOdd || empty($resourceTpl)) && !empty($tplLast)) {
                      $resourceTpl = parseTpl($tplLast, $properties);
                  }
              ...
              


              Hope this helps anybody with this issue.