You can’t break out of PHP in a MODx snippet. The usual method is:
<?php
$output = 'HTML CODE';
// php code
$output .= 'MORE HTML CODE';
//php code
return $output;
?>
To execute another snippet, you need to use:
http://wiki.modxcms.com/index.php/API:runSnippet
Is this a situation where the practice was discouraged in the past and is finally being enforced in 1.0.1? I definitely have snippets that break out of PHP and work just fine under 1.0.0 and previous. Obviously I’ll rewrite my snippets the CORRECT way, but I’ve been doing it because it worked.
Thanks for the help.
Des
webandflowdesign.com
Or use the api-function parseChunk:
// Set placeholders-array:
$ph_array['linkUrl']='yourlinkurlstring';
$ph_array['lastvisit']='yourlastvisitvalue';
return $modx->parseChunk('nameOfChunk', $ph_array, '[+', '+]');
-
MODX Staff
- 730 Posts
Quote from: webandflow at Oct 26, 2009, 11:14 PM
I’ve got a number of snippets that use blocks of escaped HTML and inline php i.e.
<?php
...some php code...
?>
<a href="<?php echo $link; ?>">link text</a>
<?php
...some more php code...
?>
If you have an example of a snippet like this that worked before 1.0.1 I’d love to take a look.
You can definitely include php files that mix php and html blocks, but even then, since snippets rely on a return value, it would make sense to use an output buffer to capture any echoed output from such an include.