Ok... I’m trying to figure out the View layer in MODx Revolution (I’m talking MVC speak here).
What I’m trying to do: use Smarty to format Snippet output. I’m trying to figure out a way to parse a template file.
Valid Snippet content is something like this, where "testChunk" is a Chunk I created:
$output = $modx->getChunk('testChunk',array(
'name' => 'John',
));
return $output;
But the problem I have with this is that this LOADS and PARSES the Chunk. Not so fast... what if I want to provide a default text string and parse that?
So in a normal MODx Revolution Snippet, the Smarty class is not included. You can include the Smarty class... but this seems incomplete because the normal Smarty methods don’t seem to work:
include_once('/path/to/core/model/smarty/Smarty.class.php');
$output .= $Smarty->fetch( '/path/to/your/sample.tpl' );
return $output;
This doesn’t work too good... not sure how I should do this... the page at
http://rtfm.modx.com/display/revolution20/Custom+Manager+Pages doesn’t cover this...
When I try the fetch or display methods, I get all kinds of errors in the MODx logs:
[2010-08-22 22:55:54] (ERROR @ /path/to/my_modx/core/model/smarty/Smarty.class.php : 1092) User error: Smarty error: the $compile_dir 'templates_c' does not exist, or is not a directory.
[2010-08-22 22:55:54] (ERROR @ /path/to/my_modx/core/model/smarty/Smarty.class.php : 1262) PHP warning: Smarty::include(templates_c/%%79^79C^79CD59B3%%sample.tpl.php) [<a href='smarty.include'>smarty.include</a>]: failed to open stream: No such file or directory
[2010-08-22 22:55:54] (ERROR @ /path/to/my_modx/core/model/smarty/Smarty.class.php : 1262) PHP warning: Smarty::include() [<a href='function.include'>function.include</a>]: Failed opening 'templates_c/%%79^79C^79CD59B3%%sample.tpl.php' for inclusion (include_path='.:/Applications/MAMP/bin/php5/lib/php')
You can see by the logs that I’m using MAMP... but WTF?