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

    I’m trying to get some PrevNext navigation to work on all the childpages of a certain folder(category); I’was thinking of creating a @INHERIT TV so I could have an input field with e.g. the following: ’sortBy=createdon||sortHow=DESC||displayTitle=false’; this would be the parameters I would need to pass to the PrevNext script.

    What I’m struggling with at the moment is how to convert a string like that to an parameter array so I could pass it to the snippet:

    here is a start:
    $tv    = $modx->getTemplateVarOutput('tvPrevNext', $modx->documentIdentifier);
    $str = $tv['tvPrevNext'];
    ....
    
    return $modx->runSnippet('PrevNext',$param);
    
    


    I guess explode(’||’,$str) would give me a first array but how do I go from there?

    Hope somebody can help.

    P.S. if somebody has a better idea of how to do this, please let me know as well.

    Thank you guys

    Thank you in advance for your input.

    Maybe, I’m a little closer - this is what I have and it seems that I’m able to set the parameters:

    $tv    = $modx->getTemplateVarOutput('tvPrevNext', $modx->documentIdentifier);
    $array = explode('|', $tv['tvPrevNext']);
    $param = array();
    foreach ($array as $key => $value) {
    	$arr = explode('=', $value);
    	
    	$param[$arr[0]] = $arr[1];
    
    }
    return $modx->runSnippet('PrevNext',$param);
    


    However, I guess there is an easier way?!
      • 7231
      • 4,205 Posts
      To loop through the array PHP has the foreach() array function:
      http://www.php.net/foreach
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 7231
        • 4,205 Posts
        Something like this might work:

        <?php
        $str = "sortBy=createdon||sortHow=DESC||displayTitle=false";
        $str = explode('||',$str);
        
        foreach ($str as $x) {
            //build the parameter string
            $x = explode('=',$x);
            $output .= '&'.$x[0].'=`'.$x[1].'` ';
        }
        
        echo $output;
        
        ?>


        Edit: Pretty much the same as you have but this should return the entire string.
        &sortBy=`createdon` &sortHow=`DESC` &displayTitle=`false`
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don&#39;t know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 19889
          • 616 Posts
          really appreciate your input - from my understanding, the second argument of runSnippet needs to be an array, so a string won’t work.
            • 7231
            • 4,205 Posts
            You are correct, here try this:
            <?php
            $tv = "tvPrevNext";
            $str = $modx -> getTemplateVarOutput( $tv, $modx->documentIdentifier, $published = 1 );
            //$str = "sortBy=createdon||sortHow=DESC||displayTitle=false";
            $str = explode('||',$str[$tv]);
            $param = array();
            
            foreach ($str as $x) {
                $x = explode('=',$x);
                $param[$x[0]] = $x[1];
            }
            
            return $modx->runSnippet('PrevNext',$param); 
            
            ?>


            Hope this works.
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 19889
              • 616 Posts
              Quote from: dev_cw at Dec 22, 2007, 03:58 PM

              You are correct, here try this:
              <?php
              $tv = "tvPrevNext";
              $str = $modx -> getTemplateVarOutput( $tv, $modx->documentIdentifier, $published = 1 );
              //$str = "sortBy=createdon||sortHow=DESC||displayTitle=false";
              $str = explode('||',$str[$tv]);
              $param = array();
              
              foreach ($str as $x) {
                  $x = explode('=',$x);
                  $param[$x[0]] = $x[1];
              }
              
              return $modx->runSnippet('PrevNext',$param); 
              
              ?>


              Hope this works.

              Thanks again - this seems to work just fine - what I was wondering in general is this: from my understanding there are two way to achieve what I want:

              1. I’ve something like this in my template: "[! call my snippet !]" - have some logic in the snippet and call the "PrevNext" snippet from here.
              2. have a chunk in my template that would call my snippet

              am I missing something - is one way better than the other or are they just about the same.
                • 7231
                • 4,205 Posts
                The way I see it is if you want to be able to modify the snippet independently of other pages then a TV will give you more flexibility. However if you are going to use the same configuration throughout the site then a chunk may be lighter on the server.
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]