View previous topic :: View next topic |
Author |
Message |
mpgjunky Smarty n00b
Joined: 25 Jul 2011 Posts: 4
|
Posted: Mon Jul 25, 2011 12:56 pm Post subject: smarty_function_eval() replacement or workaround? |
|
|
Hi,
I am using Smarty v3.0.6 and noticed that the plugin function.eval.php is missing. Does anyone know of a replacement method or workaround?
Cheers,
Michael. |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
|
Back to top |
|
mpgjunky Smarty n00b
Joined: 25 Jul 2011 Posts: 4
|
Posted: Mon Jul 25, 2011 2:15 pm Post subject: |
|
|
Thanks for the quick reply.
I am actually trying to fix the ArraySmarty renderer for Pear HTML_QuickForm. The renderer was written ages ago, pre version 3 and has not been updated since.
The trouble is with a code snippet that needs evaluating, and returned to the renderer, not displayed immediately.
Specifically:
Code: | $renderer->setRequiredTemplate(
'{$label}
{if $required}
<span style="color:#FF0000;font-size:16px"><sup>*</sup></span>
{/if}'
); |
...needs to be evaluated. The end result would be the field label + the "*" to indicate a required field.
Any ideas?
Cheers,
Michael. |
|
Back to top |
|
mpgjunky Smarty n00b
Joined: 25 Jul 2011 Posts: 4
|
Posted: Mon Jul 25, 2011 2:17 pm Post subject: |
|
|
PS: This is the code that references the old eval plugin:
Code: | function _tplFetch($tplSource)
{
if (!function_exists('smarty_function_eval')) {
require SMARTY_DIR . '/plugins/function.eval.php';
}
return smarty_function_eval(array('var' => $tplSource), $this->_tpl);
}// end func _tplFetch
|
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Jul 25, 2011 2:24 pm Post subject: |
|
|
FYI, you can eval a string from PHP like this:
Code: | $output = $smarty->fetch("eval:$string"); |
Maybe that will be useful for you. |
|
Back to top |
|
mpgjunky Smarty n00b
Joined: 25 Jul 2011 Posts: 4
|
Posted: Mon Jul 25, 2011 2:57 pm Post subject: |
|
|
mohrt wrote: | FYI, you can eval a string from PHP like this:
Code: | $output = $smarty->fetch("eval:$string"); |
Maybe that will be useful for you. |
Thanks mohrt, that seems to be just what was needed! |
|
Back to top |
|
jrcajdie Smarty n00b
Joined: 15 Mar 2013 Posts: 1
|
Posted: Fri Mar 15, 2013 2:41 pm Post subject: |
|
|
Hello. I need help. I have been searching for hours for a workaround to make PEAR ArraySmarty.php work with Smarty 3 and only had found this.
Could you tell me if you got this to work and tell me how.
Thanks in advance. |
|
Back to top |
|
periklis Smarty n00b
Joined: 17 Mar 2011 Posts: 1
|
Posted: Fri Apr 19, 2013 10:16 am Post subject: |
|
|
As mpgjunky and mohrt suggested, here's what you have to do:
Replace the function _tplFetch() inside ArraySmarty.php with:
Code: | function _tplFetch($tplSource)
{
return ($this->_tpl->fetch("eval:$tplSource"));
}// end func _tplFetch
|
(You'll have to do other stuff later, like replace _clear_assign() with clearAssign(), but that's easy) |
|
Back to top |
|
|