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

Function defined in subtemplate is no longer defined #301

Closed
machavity opened this issue Oct 7, 2016 · 12 comments
Closed

Function defined in subtemplate is no longer defined #301

machavity opened this issue Oct 7, 2016 · 12 comments

Comments

@machavity
Copy link

I've pretty much run out of issues on my end to explain this so I'm starting to think it's the migration to 3.1.30 that's causing this. It's my only Smarty migration issue thus far

I have a template that loads some subtemplates to generate HTML for an email. One of them defines a function
{function name="email_button"}Some HTML{/function}

The master template includes it first
{include file="./shared_functions.tpl"}

After the 3.1.30 upgrade it fails

PHP Fatal error: Uncaught --> Smarty: Unable to find template function 'email_button' <--
thrown in /path/lib/Smarty/sysplugins/smarty_internal_runtime_tplfunction.php on line 56

I'm still trying to narrow down where in Smarty it does this but I was able to get it to do it for my development environment and doing a pull of everything in Smarty master doesn't fix it.

@uwetews
Copy link
Contributor

uwetews commented Oct 8, 2016

Template function processing has been update in the master branch today .
Could you please check if this did resolve also your problem?

@machavity
Copy link
Author

Finally was able to set up a test for this and it seems to work in .31-34

@machavity
Copy link
Author

machavity commented Oct 13, 2016

I spoke too soon. Not sure why, but it's throwing that error again. Why it didn't fail on my Dev is still a mystery. But -34 didn't fix it after all

The line has changed from 56 to 49

@machavity machavity reopened this Oct 13, 2016
@uwetews
Copy link
Contributor

uwetews commented Oct 19, 2016

You say it does run on your DEV system but not on other installation.
Can you please check what happens if you delete manually all existing compiled and cached template files

@machavity
Copy link
Author

I don't think that's the issue. We use DevOps to release our code, and when we do a new release it creates a new cache directory. I did a release today and confirmed there's no cache in there afterward.

@uwetews
Copy link
Contributor

uwetews commented Oct 19, 2016

Could you please send me all templates source of a page which does fail (private uwe.tews@googlemail.com)

@machavity
Copy link
Author

I don't think it would help unfortunately. I've tried to mock something up internally that emulates what's going on here in a simpler way, but I can't get it to fail at all outside this one script. The frontend controller is also very complex, so just getting data back into it that causes this failure has been a pain (and it's a cron job so mocking it into Apache for easier execution has been another pain).

I have finally gotten this script to reliably fail on my Dev server and here's what I've found in back tracing this so far.

  1. The function is parsed and defined correctly. It exists in $tpl->tplFunctions after parsing
  2. The template generates the correct call in the cached template and in the final PHP for actually running the page
    <?php $_smarty_tpl->smarty->ext->_tplFunction->callTemplateFunction($_smarty_tpl, 'email_button', array('button_link'=>"some link here",'button_text'=>"Button Text",'font_size'=>1.3,'align'=>"center",'button_width'=>"300px"), true);?>
  3. When the call gets back around to execution time, the array of template defined functions is empty

Here's the backtrace I got from the Exception Smarty throws, if that helps

0 /lib/Smarty/sysplugins/smarty_resource_recompiled.php(52) : eval()'d code(23): Smarty_Internal_Runtime_TplFunction->callTemplateFunction(Object(Smarty_Internal_Template), 'email_button', Array, true)
1 /lib/Smarty/sysplugins/smarty_template_resource_base.php(128): content_580900a2b225b6_40085362(Object(Smarty_Internal_Template))
2 /lib/Smarty/sysplugins/smarty_template_compiled.php(171): Smarty_Template_Resource_Base->getRenderedTemplateCode(Object(Smarty_Internal_Template))
3 /lib/Smarty/sysplugins/smarty_internal_template.php(192): Smarty_Template_Compiled->render(Object(Smarty_Internal_Template))
4 /lib/Smarty/sysplugins/smarty_internal_templatebase.php(200): Smarty_Internal_Template->render(false, 0)
5 /lib/Smarty/sysplugins/smarty_internal_templatebase.php(100): Smarty_Internal_TemplateBase->_execute(Object(Smarty_Internal_Template), NULL, NULL, NULL, 0)
6 /compile/smarty_php^3bde0029043ac56cbd64628e314d9feff572dcc5_0.file.message.tpl.php(42): Smarty_Internal_TemplateBase->fetch()
7 /lib/Smarty/sysplugins/smarty_template_resource_base.php(128): content_57f69319ac9d74_36307871(Object(Smarty_Internal_Template))
8 /lib/Smarty/sysplugins/smarty_template_compiled.php(171): Smarty_Template_Resource_Base->getRenderedTemplateCode(Object(Smarty_Internal_Template))
9 /lib/Smarty/sysplugins/smarty_internal_template.php(192): Smarty_Template_Compiled->render(Object(Smarty_Internal_Template))
10 /lib/Smarty/sysplugins/smarty_internal_template.php(358): Smarty_Internal_Template->render()
11 /compile/smarty_php^fd72124eebd4afc4bdc4ad84156fe95f66786f41_0.file.display.tpl.php(161): Smarty_Internal_Template->_subTemplateRender('/var/www/user/...', NULL, '/path.com/...', 0, 3600, Array, 0, true)
12 /lib/Smarty/sysplugins/smarty_template_resource_base.php(128): content_57fe8d17187d38_44604288(Object(Smarty_Internal_Template))
13 /lib/Smarty/sysplugins/smarty_template_compiled.php(171): Smarty_Template_Resource_Base->getRenderedTemplateCode(Object(Smarty_Internal_Template))
14 /lib/Smarty/sysplugins/smarty_internal_template.php(192): Smarty_Template_Compiled->render(Object(Smarty_Internal_Template))
15 /lib/Smarty/sysplugins/smarty_internal_templatebase.php(200): Smarty_Internal_Template->render(false, 0)
16 /lib/Smarty/sysplugins/smarty_internal_templatebase.php(100): Smarty_Internal_TemplateBase->_execute(Object(Smarty_Internal_Template), NULL, NULL, NULL, 0)
17 /classes/cms/general.php(47): Smarty_Internal_TemplateBase->fetch('email/display.t...')
18 /classes/cms/contact/email.php(303): CMS\General::displayShared('display.tpl', Object(OCG\Smarty), 'email/')
19 /classes/cms/contact/email.php(330): CMS\Contact\Email->buildMail('message.tpl', 'someMailHere', 'Subject', false, true)
20 /classes/crm/sales/funnel/message.php(735): CMS\Contact\Email->sendMail(NULL, Array, Subject')
21 /classes/crm/sales/funnel/message.php(694): Crm\Sales\Funnel\Message->sendMailEmail(240258)
22 /classes/crm/sales/funnel/message.php(593): Crm\Sales\Funnel\Message->sendMailProcess(Array)
23 /var/www/user/joel/test.com/smarty.php(37): Crm\Sales\Funnel\Message->sendMail()
24 {main}

I'm still digging into this to narrow it down. This is all I have thus far

@uwetews
Copy link
Contributor

uwetews commented Oct 22, 2016

Which CMS system is it? Where can I find the code?

@uwetews
Copy link
Contributor

uwetews commented Oct 23, 2016

From your dump I can see that the CMS is calling a lot of templates by fetch().
It's possible that because of some internal changes as template object caching in your case created some unexpected side effects.

The master branch is now updated with some improvement that may have solved also your problems.
could you please check?

@machavity
Copy link
Author

This is a custom CMS we've written in-house. 31-dev/39 didn't fix it. I've run through everything I can think of in trying to find the problem, but, despite the function getting defined, it doesn't appear that it gets translated into the Smarty object being passed down the line. It's baffling

I emailed you the templates in question. I've reached the end of my rope.

uwetews added a commit that referenced this issue Oct 27, 2016
…een Smarty::fetch() and Smarty::display() calls

    #301
@uwetews
Copy link
Contributor

uwetews commented Oct 27, 2016

Finally found the bug.
The fix is in the master branch

@uwetews uwetews closed this as completed Oct 27, 2016
@machavity
Copy link
Author

Yep, confirmed fixed. Thanks a ton!

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