|
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 |
Synchro Smarty Regular
Joined: 27 Apr 2008 Posts: 43
|
Posted: Mon Apr 27, 2015 2:57 pm Post subject: Plugins not loading from compiled template |
|
|
I'm running into an odd problem since I switched to using smarty from composer instead of my own local copy. It all works fine on the first hit (i.e. when compiling after clearing compiled templates), but not on subsequent hits - there must be a different plugin loading/resolving mechainism for each scenario.
I have a smarty subclass that defines an additional plugins dir. My installation test is happy with it:
Code: | Smarty Installation test...
Testing template directory...
/Users/marcus/Sites/mysite/templates is OK.
Testing compile directory...
/Users/marcus/Sites/mysite/templates_c is OK.
Testing plugins directory...
/Users/marcus/Sites/mysite/includes/vendor/smarty/smarty/libs/plugins is OK.
/Users/marcus/Sites/mysite/includes/smarty is OK.
Testing cache directory...
/Users/marcus/Sites/mysite/cache is OK.
Testing configs directory...
/Users/marcus/Sites/mysite/configs is OK.
Testing sysplugin files...
... OK
Testing plugin files...
... OK
Tests complete. |
You can see that the first plugin dir listed is the untouched stock plugins folder. I'm calling addPluginDir (note not setPluginDir, though I have tried it that way too, wih the same results) once with the extra folder, and that's setting the second plugins path successfully.
So, with all that looking OK, I then get this error later on the same page:
Code: | Fatal error: Call to undefined function smarty_modifier_date_format() in /Users/marcus/Sites/mysite/templates_c/96/17/54/9617542f88db4fc525ac48122d35bd6616a0bcde_0.file.login.tpl.php on line |
That is a standard plugin defined in the default plugin dir, not something I have made. Given that the path is set correctly ( in this case "/Users/marcus/Sites/mysite/includes/vendor/smarty/smarty/libs/plugins/modifier.date_format.php" exists and is readable), the only cause I can think of is that it is failing to load the plugin files. I've not found how it loads them - does smarty pre-emptively load all plugins, or does it rely on an error trap to try and lazy-load plugins ony when they are called? Of is there some ordering issue in the paths? Ownership and permissions are all as expected.
I see that some plugins are loaded like this example:
Code: | require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
|
I assume there must be some similar loading pattern for custom plugins that takes multiple locations into account, but I've not found where that is.
Any ideas? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Apr 27, 2015 4:05 pm Post subject: |
|
|
Simple Test Case? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Apr 27, 2015 6:30 pm Post subject: |
|
|
Which Smarty version did you load by composer?
Does /Users/marcus/Sites/mysite/templates_c/96/17/54/9617542f88db4fc525ac48122d35bd6616a0bcde_0.file.login.tpl.php contain something similar like:
if (!is_callable('smarty_modifier_date_format')) require_once 'C:/wamp/www/Smarty3.1-test-release/vendor/smarty/smarty/libs/plugins/modifier.date_format.php'; ? |
|
Back to top |
|
Synchro Smarty Regular
Joined: 27 Apr 2008 Posts: 43
|
Posted: Mon Apr 27, 2015 7:44 pm Post subject: |
|
|
I'm running dev-master for the compiled template clearing bug workaround.
I have structures similar to that, for example this one is clearly loading my custom plugin, and seems happy:
Code: | if (!is_callable('smarty_function_helpicon')) require_once '/Users/marcus/Sites/mysite/includes/smarty/function.helpicon.php';
|
The compiled line that's throwing the error is simply:
Code: | <?php echo smarty_modifier_date_format(time(),"%Y");?>
|
So not even any variables in that! That's also the only instance of the use of that modifier in the template. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Apr 27, 2015 9:20 pm Post subject: |
|
|
You did not answer my question if
/Users/marcus/Sites/mysite/templates_c/96/17/54/9617542f88db4fc525ac48122d35bd6616a0bcde_0.file.login.tpl.php
did contain code to require modifier.date_format.php?
can you simplify login.tpl just to the failing tag and provide the complete compiled template code? |
|
Back to top |
|
Synchro Smarty Regular
Joined: 27 Apr 2008 Posts: 43
|
Posted: Mon Apr 27, 2015 10:07 pm Post subject: |
|
|
Sorry, I thought I'd implied that - no, the compiled template does not try to require the date_format modifier.
The template structure is somewhat complex, but I've cut it back to a minimal example.
My script displays t1.tpl, which looks like this:
Code: | {extends file="layout.tpl"}
{block name="body"}
{/block}
|
layout.tpl contains this:
Code: | {block name="footer"}
{include file="footer.tpl"}
{/block}
|
and footer.tpl contains just this:
Code: | {$smarty.now|date_format:"%Y"}
|
If I move the date tag into t1.tpl or layout.tpl, it works fine. It's ONLY when it is in the footer template that the problem occurs.
The above renders into this compiled template:
Code: | <?php /* Smarty version 3.1.22-dev/19, created on 2015-04-27 21:54:47
compiled from "./templates/t1.tpl" */ ?>
<?php
/*%%SmartyHeaderCode:1979663769553eb0272bd437_27075992%%*/
if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'7ec43ee468a652e38e08582dd00c6cb7d1b322a7' =>
array (
0 => './templates/t1.tpl',
1 => 1430171662,
2 => 'file',
),
'f81f9f27887e3850bbeea9aaab155ff0d7e7a27a' =>
array (
0 => './templates/layout.tpl',
1 => 1430171687,
2 => 'file',
),
'fe2e19b7749631faa1ea6df65c839656941f0595' =>
array (
0 => './templates/footer.tpl',
1 => 1430171596,
2 => 'file',
),
),
'nocache_hash' => '1979663769553eb0272bd437_27075992',
'has_nocache_code' => false,
'version' => '3.1.22-dev/19',
'unifunc' => 'content_553eb0273606f3_48360162',
),false);
/*/%%SmartyHeaderCode%%*/
if ($_valid && !is_callable('content_553eb0273606f3_48360162')) {
function content_553eb0273606f3_48360162 ($_smarty_tpl) {
?>
<?php
$_smarty_tpl->properties['nocache_hash'] = '1979663769553eb0272bd437_27075992';
/* Call merged included template "footer.tpl" */
echo $_smarty_tpl->getInlineSubTemplate("footer.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), 0, '1596369605553eb02733b907_14964681', 'content_553eb02733a592_59309290');
/* End of included template "footer.tpl" */?>
<?php }
}
?><?php
/*%%SmartyHeaderCode:1596369605553eb02733b907_14964681%%*/
if ($_valid && !is_callable('content_553eb02733a592_59309290')) {
function content_553eb02733a592_59309290 ($_smarty_tpl) {
?>
<?php
$_smarty_tpl->properties['nocache_hash'] = '1596369605553eb02733b907_14964681';
echo smarty_modifier_date_format(time(),"%Y");?>
<?php
/*/%%SmartyNocache:1596369605553eb02733b907_14964681%%*/
}
}
?> |
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Apr 27, 2015 11:44 pm Post subject: |
|
|
Thank's for bringing this up.
It was a bug in the github dev-master version.
It's now fixed. |
|
Back to top |
|
Synchro Smarty Regular
Joined: 27 Apr 2008 Posts: 43
|
Posted: Tue Apr 28, 2015 6:48 am Post subject: |
|
|
Yep, that fixes it for me, thanks very much. |
|
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
|
|