We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1295
    • 2 Posts
    Hello.
    Can someone help me with this?

    I have a snippet which contains something like this:
    	$params = array(
    		'code' => 'A',
    		'name' => 'B',
    		'value' => 'C'
    	);
    
            return $modx->parseChunk('ATpl', $params, '[+', '+]');
    


    The chunk ATpl is this:
    <p>[+code+] ..... [+name+] ..... [+value+]</p>
    


    When using the snippet on a web page, I get this error:
    Fatal error: Call to a member function parseChunk() on a non-object in /home/dailyinf/public_html/manager/includes/document.parser.class.inc.php(769) : eval()’d code on line 69

    Same thing happens if I’m using setPlaceholder & getChunk.

    What am I doing wrong?

    PS: I’m new to MODx, so I’m pretty sure I did something stupid smiley
      • 3749
      • 24,544 Posts
      That usually means the $modx object is not available at that point in your code. If the code is inside a function, you have to put:

      global $modx;


      at the top of the function in order to let PHP know that you mean it to use the $modx object from outside the function rather than creating a new one.

      If that doesn’t work, sometimes you need to pass $modx as an argument to the function containing the code.
        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
        • 1295
        • 2 Posts
        Yes, that was it. Thank you very much.