Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch:{eval} in PHP function no longer works with assigned values from function #152

Closed
strikernl opened this issue Jan 5, 2016 · 2 comments

Comments

@strikernl
Copy link

With Smarty 3.1.21 the following used to work:

require 'smarty-3.1.21/libs/Smarty.class.php';

$s = new Smarty();
$s->registerPlugin('function', 'myTestFunction', 'myTestFunction');
$s->display('test.tpl');

function myTestFunction ($params, $smarty) {
    $smarty->assign('value', $params['testvalue']);
    return $smarty->fetch('eval:' . $params['testhtml']);
}

Contents of test.tpl:

test value: {myTestFunction testvalue='5' testhtml='"{$value}"'}

The output would be as follows:

test value: "5"

However, the same code with 3.1.29 loaded gives me the following result:

test value: ""

Is this expected behaviour, is there something I am supposed to be doing differently since some version after 3.1.21? Or is this a bug?

uwetews added a commit that referenced this issue Jan 28, 2016
…nt parameter should default to the calling template object #152
@uwetews
Copy link
Contributor

uwetews commented Jan 28, 2016

The root cause is that in Smarty 3 the 2nd parameter of plugins is the calling template object but not the Smarty object.
Correctly it should be

function myTestFunction ($params, $template) {
    $template->smarty->assign('value', $params['testvalue']);
    return $template->smarty->fetch('eval:' . $params['testhtml']);
}

There is a fallback that you can call must methods also on a template object and some link got broken in your example.

The fix is now in the master branch and will late be included in 3.1.30

@uwetews uwetews closed this as completed Jan 28, 2016
@strikernl
Copy link
Author

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants