-
Notifications
You must be signed in to change notification settings - Fork 715
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
Regression in 3.1.28 - extendsall resource type before template file name doesn't work #123
Comments
I can't reproduce your problem. If I use something like {include file="extendsall:template.html"} the resource gets loaded from the plugins folder. Note: The file name is resource.extendsall.php, not resource_extendsall.php or was it just a typo? I also do not understand your comment regarding the prefilter under 3.1.27. |
First of all - of course I've made mistake with extendsall resource plugin file - it was and it's named resource.extendsall.php ;-) In 3.1.27 I've used the following code: class Smarty_Prefilter_Extendsall_Include {
static public function prefilter_extendsall_include($tpl_source, Smarty_Internal_Template $template) {
if (is_array($template->smarty->template_dir) === false)
return $tpl_source;
// prepend all files in {include} blocks with resource type 'extendsall:'
return preg_replace('#(\{include\s*file=[\'"])(?:(?![a-z]+:|/|\{))(.+)([\'"][^}]*\})#i', '$1extendsall:$2$3', $tpl_source);
}
} to automatically prepend template file name with 'extendsall:' in all inclusions inside template file. |
How did you make the filter known? $smarty->registerFilter('pre',array('Smarty_Prefilter_Extendsall_Include', 'prefilter_extendsall_include')); and it worked. |
Exactly the same as you wrote. |
Uwe, have a look at problem demonstration which I've prepared. You can download it from: |
You have general design problem. I would also get rid of the pre-filter as you may get results you don't expect by the template code. |
The assumption with previous smarty version was that when I extend 'data1.html' first time I can modify content from dynamically loaded plugins - templates2 in such example is plugin template directory (first directory from template directory list), so data1.html from templates2 had been used already and smarty, knowing about that, took into account data1.html from templates1 avoiding endless loop / recursion. That was very cool feature which allows us to construct plugins which hide original template from application core, but at the same time allow to use template content from core without rewriting all... |
I need to think about it, might take a few days.... |
Nice to hear that. Uwe, who personally gets payments after clicking "Donate" (Paypal) on smarty.net www site? |
Perhaps I get a Christmas present.... lol |
Why do you need the {extends 'data1.html'} in templates2/data1.html ? |
I've asked about "Donate" button, because I'd like to pay voluntarily 10$ monthly. I know that open source projects always suffer from underfunding, so when most smarty users would pay 10$ monthly (I'm pretty sure they do their bussiness quite well thank to Smarty) the project would be much more vital ;-) |
So if I'll remove {extends file="data1.html'} from templates2/data1.html from templates1/data1.html |
As I said before {extends} must never use same template name as the calling one. Instead of using the prefilter can $smarty->setDefaultResourceType('extendsall'); to change the default resource type from file to extendsall. Your donates will be always wellcome. |
As I see when I'll use data1.html localised by template dir chain in this order:
templates2/data1.html will be loaded only and templates1/data1.html will not? {extends file="data1.html"} both file were loaded, and first one could manipulate block contents defined in second one. In Smarty < 3.1.28: $smarty->setDefaultResourceType('extendsall'); caused template file load errors so as workaround I had to use prefilter. |
Ok I've changed index.php from previous test application to: include('smarty.git/libs/Autoloader.php');
Smarty_Autoloader::register();
$SMARTY = new Smarty;
$SMARTY->addPluginsDir('SmartyPlugins');
$SMARTY->setDefaultResourceType('extendsall');
$SMARTY->setTemplateDir(null);
$SMARTY->AddTemplateDir(array('templates2', 'templates1'));
$SMARTY->setCompileDir('templates_c');
$SMARTY->display('template.html'); and this is the only changed file. $SMARTY->setDefaultResourceType('extendsall'); and with git master HEAD the generated content is blank (no HTTP error). With 3.1.28 content is generated partly - only from header block :( |
$SMARTY->setDefaultResourceType('extendsall'); sorry, it did require a bugfix which is now in the master branch. You must use the newest resource.extendsall.php which you did not in the provided example |
I did: git pull on smarty repo local copy and it seems to work ;-) Thanks a lot, Uwe! |
Anyway it was an interesting use case of extendsall. |
I've found another bug: when we prepend template dir chain with templates_3 directory and put data1.html file there with the following content: {block name="content-data1" prepend}
<p>data1 from templates3</p>
{/block} after reload page in web browser we get HTTP 500 error. To resolve the problem we have to clear smarty compiled templates' cache. Then it works again. Any change in template dir chain requires clearing cache :( |
PHP error log shows:
It seems that templates are not recompiled "magically" after template directory chain change, because [1]template.html is invalid if we have 3 template dirs in chain. |
Grr I see what happens when you change your template_dir settings. I have today no time left. I will look into it tomorrow |
No problem - there is no pressure :) Thanks in advance for problem investigation. |
The fix (resource.extendsall.php) is now in the master branch |
I confirm that commit mentioned above resolves my problem. |
Me again. You may also use $smarty->setMergeCompiledIncludes(true); With this setting Smarty create a single compiled file containing all template code. Another note: You may place a {strip} tag at the beginning of the template files to get rid of empty lines, or enable it for certain section with {strip} {/strip}. btw I added your special use case to our PHPunit tests. Hopefully we not run again in future into problems like this Regars Uwe |
Great to hear that - after git pull works like a charm ;-) |
By the way, I have released 3.1.29 |
Wow, I'll update smarty requirement in my application very soon ;-) |
It took a while to sort all things out. But the case to use extendsall over all levels of templates and sub-templates including inheritance was also a bit new to me. I think we have now removed all ambiguousness in template and script code, Small hint $SMARTY->setTemplateDir(null);
$SMARTY->addTemplateDir(array('templates2', 'templates1')); can be replaced by $SMARTY->setTemplateDir(array('templates2', 'templates1')); |
Uwe, in this example we can do that, but in my real application plugins add their own template directories and I accidentally left this as two method calls ;-) |
Hi Uwe, I've tried to port my application to Smarty 3.1.29 with hope that everything will be all right, but it didn't play well :( {include file="toolbar.html"} causes loading all other contents after include. |
Hello, hello? Anybody's here? ;-) |
Hello, Uwe.... ? |
When we use
{include file="extendsall:template.html"}
in our template, extendsall is not supported at all in 3.1.28.
File which defines extendsall resource type is original resource.extendsall.php file from tgz package (demos/plugins/resource_extendsall.php) and is placed in /path/to/application/plugins directory added to plugin dirs by the following code:
In 3.1.27 workaround with prefilter replacing {include file="template.html"} by {include file="extendsall:template.html"} was a solution.
The text was updated successfully, but these errors were encountered: