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

    I’m using a snippet several times in the same page, and I’m transfering to it deffrent variables each time (&var=`value`).
    The problem is that the snippets runs each time with the variable from the last call to the snippet.
    e.g.:
    If I have the following calls to the snippet:
    [[snippet? &var=`one`]]
    [[snippet? &var=`two`]]
    [[snippet? &var=`three`]]

    Then all the three outputs, will be according to the &var=`three` and the snippet ignores any other variable in the previous calls.
    How can I fix this?

    Thanx
      • 22303 MODX Staff
      • 10,725 Posts
      Please post your snippet code and perhaps we can tell you what’s wrong...
        • 4369
        • 31 Posts
        k, here’s the snippet:

        <?
        require_once('assets/snippets/feed.inc.php');
        
        $feedUrl = (isset($url)) ? $url : null;
        $feedType = (isset($feedType)) ? $feedType : null;
        $feedAmountItems = (isset($feedAmountItems)) ? (int) $feedAmountItems : 10;
        $feedLayoutOuter = (isset($feedLayoutOuter)) ? $feedLayoutOuter : 'FeedsLayout_Outer';
        $feedLayoutInner = (isset($feedLayoutInner)) ? $feedLayoutInner : 'FeedsLayout_Inner';
        
        $feed = new feed();
        $feed->feed_url($feedUrl);
        
        $output = null;
        $itemOutput = null;
        $feedOutput = null;
        
        if ($feed->data){
        	$max = $feed->get_item_quantity($feedAmountItems);
        	for ($x = 0; $x < $max; $x++) {
        		$item = $feed->get_item($x);
        		$itemOutput = '<a href="' . $item->get_permalink() . '">' . $item->get_title() . '</a>';
        		$feedOutput .= str_replace('[+itemContent+]', $itemOutput, $modx->getChunk('FeedsLayout_Inner'));
        	}
        	$modx->setPlaceholder('feedContent', trim($feedOutput));
        	$output = $modx->getChunk($feedLayoutOuter);
        }
        $feed = null;
        return $output;
        


        I call the snippet like this:

        [!Snippet? &url=`file.xml`!]
        [!Snippet? &url=`file2.xml`!]
        
          • 22303 MODX Staff
          • 10,725 Posts
          Simple misuse of placeholders. You need to use instance specific placeholder names, or use something like $modx->parseChunk (or a simple str_replace call), to replace those variables in the chunk within the scope of the snippet itself.