|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
sviver Smarty Rookie
Joined: 14 Jun 2006 Posts: 6
|
Posted: Mon Jun 19, 2006 7:38 pm Post subject: A simple compile method |
|
|
If you want to compile templates without displaying them (for example compile all .tpl files, and set templates_c readonly):
1) In Smarty.class.php add a new parameter to the fetch() method:
Code: | function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false, $compileonly=false)
|
2) Modify the fetch method not to include the compiled template, if this parameter is true:
Code: | // if we just need to display the results, don't perform output
// buffering - for speed
$_cache_including = $this->_cache_including;
$this->_cache_including = false;
if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) {
if ($this->_is_compiled($resource_name, $_smarty_compile_path)
|| $this->_compile_resource($resource_name, $_smarty_compile_path))
{
if (!$compileonly) {
include($_smarty_compile_path);
}
}
} else {
|
3) Create a new compile method:
Code: | /**
* compiles the template
*
* @param string $resource_name
* @param string $cache_id
* @param string $compile_id
*/
function display($resource_name, $cache_id = null, $compile_id = null)
{
$this->fetch($resource_name, $cache_id, $compile_id, true, true);
} |
|
|
Back to top |
|
gektor Smarty n00b
Joined: 25 Jun 2006 Posts: 1
|
|
Back to top |
|
sorin Smarty n00b
Joined: 03 Sep 2006 Posts: 4
|
Posted: Sun Sep 03, 2006 4:18 pm Post subject: |
|
|
Sounds good, but what about just checking to see if a template is valid and displaying any errors found?
Something like checktemplate() that would either return true or an error message? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun Sep 03, 2006 6:53 pm Post subject: |
|
|
I've posted these before, but am too lazy to search...add these methods to your extended Smarty class -- no modifications to the Smarty code required.
[php:1:71eb4e788c] /**
* fetch's a template without saving to disk
*/
public function fetch_eval($template_source='')
{
if( !empty( $template_source ) ) {
$this->_compile_source( 'evaluated template', $template_source, $_var_compiled );
ob_start();
$this->_eval( '?>' . $_var_compiled );
$_contents = ob_get_contents();
ob_end_clean();
return( $_contents );
}
}
/**
* fetch's a template's compiled source without saving to disk
*/
public function fetch_compiled($template_source='')
{
if( !empty( $template_source ) ) {
$this->_compile_source( 'evaluated template', $template_source, $_var_compiled );
return( $_var_compiled );
}
}
[/php:1:71eb4e788c] |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|