This works - template is loaded and snippet works "test" and "hello" are printed
echo "test";
if ( !isset ($type) ) {
function test () {
echo "hello";
}
test();
}
But if I write this it won’t work - template is not loading only "test" is printed.
echo "test";
function test () {
echo "hello";
}
if ( !isset ($type) ) {
test();
}
Why???
-
MODX Staff
- 10,725 Posts
It’s recommended that you not echo or print output in a snippet. The proper way is to return content from the snippet execution. This is so you can better control where that content is output, and also a result of the fact that snippets are currently eval()’d and content returned within an output buffer.
But why the first example work ok then?
I’ll try to write it with return statement in the evening...