We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29163
    • 18 Posts
    I’m understanding the concepts of plugins (vs snippets) I think - so that PHP code is directly associated with events in the Modx Parser stages. What I don’t understand and can not find anywhere is how to actually use logic and variables that are generated during these phases to the page.

    I’ve tried running a simple test with $_SESSION variables to try and test some output, which I’ll use here to try and get a conversation started around a working example.

    In a snippet call I’ve placed:

    <?php
    	if ( !isset($_SESSION['num_visits']) ) {
    		$_SESSION['num_visits'] = 1;
    	} else {
    		$_SESSION['num_visits'] += 1;
    	}
    	
    	$content = 'You have been to this page '.$_SESSION['num_visits'].' time(s)';
    
    	echo $content;
    ?>


    (Note: I did not include session_start() as I assumed that Modx would already have called this function, and judging by the snippet output I think I’m correct in assuming that)

    The problem with the above snippet is that every time I go to the template where this snippet is called, it increments in 3’s or more (depending on the page content, tvs, etc). I wanted to create a plugin so I could call this session incrementing one time every time the page was hit, so I loaded this data into a plugin with the ’OnWebPagePrerender’ function checked. This is where I get lost. I’m assuming that I don’t call a plugin the way I would call a snippet, as it’s output would be loaded into the $modx object, but I don’t know how to properly load data into that object, or get it out of it.

    Any help is greatly appreciated!

      Tabor Carlton // Interactive Art Director
      http://www.taborcarlton.com
      http://www.alternative-media.net