Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

smarty_function_eval() replacement or workaround?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
mpgjunky
Smarty n00b


Joined: 25 Jul 2011
Posts: 4

PostPosted: Mon Jul 25, 2011 12:56 pm    Post subject: smarty_function_eval() replacement or workaround? Reply with quote

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
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Mon Jul 25, 2011 1:54 pm    Post subject: Reply with quote

{eval} is still available: http://www.smarty.net/docs/en/language.function.eval.tpl

for performance reasons you should avoid it whenever possible. Depending on your use-case, {include file="string:{$yourContentToEval}"} may be the better choice. http://www.smarty.net/docs/en/template.resources.tpl
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
mpgjunky
Smarty n00b


Joined: 25 Jul 2011
Posts: 4

PostPosted: Mon Jul 25, 2011 2:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
mpgjunky
Smarty n00b


Joined: 25 Jul 2011
Posts: 4

PostPosted: Mon Jul 25, 2011 2:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Jul 25, 2011 2:24 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mpgjunky
Smarty n00b


Joined: 25 Jul 2011
Posts: 4

PostPosted: Mon Jul 25, 2011 2:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
jrcajdie
Smarty n00b


Joined: 15 Mar 2013
Posts: 1

PostPosted: Fri Mar 15, 2013 2:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
periklis
Smarty n00b


Joined: 17 Mar 2011
Posts: 1

PostPosted: Fri Apr 19, 2013 10:16 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP