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

    I have this snippet code:
    <?php
    //var's
    $filename = "assets/files/news.txt";
    $split_rule = ":;";
    $split_part = "::";
    $mode = (isset($n_int_mode));
    
    if ($mode == null){
     $mode = `0`;
    }
    
    //read
    $file = file_get_contents($filename);
    
    //split the articles
    $rule = explode($split_rule, $file);
    
    //debug
    echo $mode;
    //debug
    
    echo "<dl class=\"\">";
    
    //check mode
    if ($mode == 0){
     //loop for each article
     for ($i=0 ;$i < (count($rule)-1);$i++){
      //split the parts from te articles
      $part = explode($split_part, $rule[$i]);
    	echo "<dt class=\"dt\"><span id=\"\" class=\"title\">";
    	echo $part[0];
    	echo "</span></dt>";
    	echo "<dd class=\"dd\"><span class=\"date\">";
    	echo $part[1];
    	echo "</span><span class=\"separator\">-</span><span class=\"autor\">";
    	echo $part[2];
    	echo "</span><span class=\"separator\">-</span><span class=\"content_1\">";
    	echo substr($part[3], 0, 150);
    	echo "</span><span class=\"content_2\">";
    	echo substr($part[3], 150, strlen($part[3]));
    	echo "</span></dd>";
     }
     echo "</dl>";
    }else{
     for ($i=0 ;$i < $mode;$i++){
      //split the parts from te articles
      $part = explode($split_part, $rule[$i]);
    	echo "<dt class=\"dt\"><span id=\"\" class=\"title\">";
    	echo $part[0];
    	echo "</span></dt>";
    	echo "<dd class=\"dd\"><!--<span class=\"date\">";
    	echo $part[1];
    	echo "</span><span class=\"separator\">-</span><span class=\"autor\">";
    	echo $part[2];
    	echo "</span><span class=\"separator\">-</span>--><span class=\"content_1\">";
    	echo substr($part[3], 0, 150);
    	echo "</span><!--<span class=\"content_2\">";
    	echo substr($part[3], 150, strlen($part[3]));
    	echo "</span>--></dd>";
     }
     echo "</dl>";
    }
    ?>


    when I call it like this --> [[nieuws? &n_int_mode=0]] and like this --> [[nieuws? &n_int_mode=1]] on 1 page both the times it are parsed like --> [[nieuws? &n_int_mode=1]]

    What can I do to make this work?

    Ivar
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Maybe that line would work if it were:
      $mode = isset($n_int_mode)? $n_int_mode : 0;
      
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 13246
        • 42 Posts
        this doesn´t work :’(
          • 24421
          • 44 Posts
          I’am a MODx beginner, but when you call the snippet, have you test to call it with backticks on the value?

          like: [[nieuws? &n_int_mode=`1`]]

          and un-cached?

          like: [!nieuws? &n_int_mode=`1`!]

          Hope this help,
          Ramon
            • 13246
            • 42 Posts
            I don’t think that mij problem is te backticks --> `
            because they are numbers/integers and so far I know integers don’t have to be quoted (in other scripting languages).

            I have found a post which seems to have the same problem.
            but I don’t understand the answer see her
              • 10487 MODX Staff
              • 1,535 Posts
              Quote from: rambat at Nov 12, 2007, 11:42 AM

              and un-cached?

              like: [!nieuws? &n_int_mode=`1`!]
              That would be my first guess, if you’re calling the snippet cached (i.e. using [[...]]) then you’ll have problems calling it twice on a single page with different parameters.
                Garry Nutting
                Senior Developer
                MODX, LLC

                Email: [email protected]
                Twitter: @garryn
                Web: modx.com
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                I think that is only useful if the snippet codes prepends (or appends) the ID to every value from the parameters, this way the first one isn’t overwritten in the MODx arrays by the last one called.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 13246
                  • 42 Posts
                  I have tryed to solve the problem with the [!...!] notation, and it works smiley

                  Thans all!