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

    Here's the idea.
    I doing a home page that is 'one page' flavored.
    This means I have - let's says 4 - sections in it and the main menu will operate a scroll down (or up ) to the relevant # (wich is basically the pagetitle got in a GR loop)

    To do this with modx I choose to create sub pages of the home and to gather the content and other data from those sub-pages in order to inject it into the home page template
    This, plus a pretty tricky Wayfinder system, gives me the wanted result (with waypoint.js, smoothscroll and so on to spice up the things).
    The first section use a GR 'first' template, the 3 others that follows, use the same GR template.

    Now, in each blocks I need a specific link to point down to the NEXT following section (the next section anchor) (in addition to the main menu). this big link will make the user to scroll down to the very next block.
    I do not see how to get this in a GR template.

    Here's the general GR tpl :
    <section id="[[!+pagetitle]]" class="text-center section-padding wayp wp2 [[!+idx]]" role="complementary">
    		 <div class="container">
                <div class="row">
                  <div class="col-md-8 col-md-offset-2">
                    <article class="contents bloc-txt">
    				[[!+content]]
    [[!+idx:incr]]
    				<a class="down-arrow-btn" href="#more-about2"><i class="glyphicon glyphicon-chevron-down"></i></a>
    				</article>
    			  </div>
                </div>
              </div>				
    </section>


    this could be done throuh JS, but I'd prefer let the page be fully generated..
    Thank you
      • 4172
      • 5,888 Posts
      you could replace getResources with something like that (untested)

      <?php
      $parent = $modx->getOption('parents',$scriptProperties,$modx->resource->get('id'));
      $outputSeparator = $modx->getOption('outputSeparator',$scriptProperties,'');
      $tpl = $modx->getOption('tpl',$scriptProperties,'');
      
      $classname = 'modResource';
      $c = $modx->newQuery($classname);
      $c->where(array('published'=>1,'deleted'=>0,'parent'=>$parent));
      $c->sortby('menuindex');
      
      $rows = array();
      if ($collection = $modx->getCollection($classname,$c)){
          foreach ($collection as $object){
              $rows[] = $object->toArray();
          }
      }
      
      $output = array();
      foreach ($rows as $key => $row){
          //get pagetitle of next row
          $nextkey = $key+1;
          $nextrow = isset($rows[$nextkey]) ? $rows[$nextkey] : array(); 
          $row['idx'] = $nextkey;
          $row['nextpagetitle'] = $modx->getOption('pagetitle',$nextrow,'');
          $output[] = !empty($tpl) ? $modx->getChunk($tpl,$row) : '<pre>' . print_r($row,1) . '</pre>';   
      }
      
      return implode($outputSeparator,$output);
      
      ?>
      


      Then you would have the next pagetitle in each tpl-chunk with
      [[+nextpagetitle]]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 36604
        • 268 Posts
        Quote from: Bruno17 at Oct 09, 2014, 01:30 PM
        you could replace getResources with something like that (untested)

        <!--?php
        $parent = $modx--->getOption('parents',$scriptProperties,$modx->resource->get('id'));
        $outputSeparator = $modx->getOption('outputSeparator',$scriptProperties,'');
        $tpl = $modx->getOption('tpl',$scriptProperties,'');
        
        $classname = 'modResource';
        $c = $modx->newQuery($classname);
        $c->where(array('published'=>1,'deleted'=>0,'parent'=>$parent));
        $c->sortby('menuindex');
        
        $rows = array();
        if ($collection = $modx->getCollection($classname,$c)){
            foreach ($collection as $object){
                $rows[] = $object->toArray();
            }
        }
        
        $output = array();
        foreach ($rows as $key => $row){
            //get pagetitle of next row
            $nextkey = $key+1;
            $nextrow = isset($rows[$nextkey]) ? $rows[$nextkey] : array(); 
            $row['idx'] = $nextkey;
            $row['nextpagetitle'] = $modx->getOption('pagetitle',$nextrow,'');
            $output[] = !empty($tpl) ? $modx->getChunk($tpl,$row) : '<pre>' . print_r($row,1) . '</pre>';   
        }
        
        return implode($outputSeparator,$output);
        
        ?>
        


        Then you would have the next pagetitle in each tpl-chunk with
        [[+nextpagetitle]]

        Thank you.

        This is a good way of reflexion but I need to keep Getressource with all its functionnabilities, see my call to undersatand:

        [[!getResources? &tpl=`GR-tpl` &tpl_0=`GR-tplFirst` &first=`8` &includeContent=`1` &sortby=`menuindex` &sortdir=`ASC`  &idx=`[[+idx]]` ]]
          • 40045
          • 534 Posts
          Maybe a combination of pdoResources and pdoNeighbours could solve your problem too, both snippets are part of the pdoTools extra, pdoResources serves very well as a faster replacement for getResources and pdoNeighbours can show prev and next resources (e.g. siblings), if it cannot output the ids of these documents, you could maybe adjust the snippet a bit or you just set the template to a chunk with no markup and probably [[+id]] as only content?!
            • 3749
            • 24,544 Posts
            You might try wrapping what you have in a getPage snippet.

              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
              • 36604
              • 268 Posts
              Quote from: exside at Oct 09, 2014, 06:52 PM
              Maybe a combination of pdoResources and pdoNeighbours could solve your problem too, both snippets are part of the pdoTools extra, pdoResources serves very well as a faster replacement for getResources and pdoNeighbours can show prev and next resources (e.g. siblings), if it cannot output the ids of these documents, you could maybe adjust the snippet a bit or you just set the template to a chunk with no markup and probably [[+id]] as only content?!

              I'd like to give it a chance, but don't find any exhaustive doc... especially for pdoressources

              I can't get pdoRessource to output anythnig, event with showlog=`1`

              I used this as a test:
              [[!pdoRessources? 
              &parents=`1` 
              &sortby=`FIELD(modResource.id, '[[*menuindex]]')`
              &sortdir=`ASC`
              &tpl=`@INLINE <li>[[+pagetitle]]</li>`
              &showLog=`1`]]
              [ed. note: elz064 last edited this post 9 years, 8 months ago.]
                • 3749
                • 24,544 Posts
                pdoRessources -> pdoResources wink
                  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