-
Notifications
You must be signed in to change notification settings - Fork 701
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
"extends"'s inheritance chain of templates with the same name #67
Comments
It can be done already.
Note that above example is dependent from the order of the template_dir's. You may set/add template_dir's also with a named index. Which may add more options. |
Uwe, thanks for the sugestion, but in your example you have to know registration order of potential application plugins. These application plugins add their individual template directories by Smarty::addTemplateDir(). Plugin creator doesn't know what other application plugins will be installed by user, so he (plugin creator) can't count on template indexes :( In meantime I've found interesting example: |
Something interesting from forum which seems to be what I exactly need: |
Yes, the 'extendsall' could work for you. You set/add template_dir's also with a named index.
Now you can change with {extends} template name and folder. |
Maybe I wasn't precise so far, so I try to give more detailed example:
|
I was just guessing. So each plugin has it's file template.html and I guess each plugin defines {block} tags with a unique name for that plugin ? How to access the plugins from user template of random name? Would this be a smarty idea? |
Yes each plugin has its template.html file which extends template.html.
user.html in core and template.html for loading from plugins, yeah? |
Uwe, I have command below in core application module: $smarty->display('extendsall:customer/customerinfo.html'); This template in core application defines some block as: {block name="customervoipaccountsbox"}
{include file="customer/customervoipaccountsbox.html"}
{/block} In plugin template directory I've prepared template customer/customerinfo.html file as below: {extends file="customer/customerinfo.html"}
{block name="customervoipaccountsbox"}
{include file="hv_accountinfobox2.html"}
{/block} I thought that it would load parent template with extending it by child template, but it was not the clue :( Am i missing anything? |
Ok that's apparently the bug in 3.1.27: if (isset($fileMatch['index'])) { You've already fixed in HEAD. When will u release 3.1.28? |
is correct. There are conditions where $fileMatch['index'] contains an empty string. |
No Uwe, it's not correct. When $fileMatch['index'] contains '0' string (it's default unnamed index for first directory in template directory list) empty() returns true, and this causes the problem which I had before proposed change. |
From php.net documentation:
|
Yes, you are right!!!! Anyway 3.1.28 does solve the problem. |
Exactly! |
Is there any way to automatically prepend all included files in template with 'extendsall:'? {include file="template.html"} in parent template? Now I have to put 'extendsall:' before template file name to avoid recursive template loading and it's not convenient :( |
Will replace the Smarty default resource type 'file' with 'extendsall'. |
I tried it before I had made changes described above, but that had finished with message:
I've noticed you had changed
|
extendsall did use internally the default resource, assuming it is 'file:'. |
I've bumped smarty to 3.1.28-dev, because last changes in resource.extendsall.php require relative changes in Smarty_Template_Source class (i.e. Smarty_Template_Source::getTimeStamp() method).
welcome/welcome.html file contains at the begining: {extends file="layout.html"} and layout.html doesn't contain {extends} blocks at all. |
This is caused now because the extendsall default resource is used also on the {extends} tag. So you have the option to add extendsall: to your {include} tags or |
For the time I use own Smarty class inherited from original one with redefined fetch method as below: class LMSSmarty extends Smarty {
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false) {
if (!is_null($template) && is_string($template) && !preg_match('/^(\/|[a-z]{2,}:)/i', $template))
$template = 'extendsall:' . $template;
return parent::fetch($template, $cache_id, $compile_id, $parent, $display, $merge_tpl_vars, $no_output_filter);
}
} That resolves default extendsall resource type for all Smarty::display() and Smarty::fetch() calls. Changing default resource type for all {include} blocks I make using prefilter definied as: class Smarty_Prefilter_Extendsall_Include {
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);
}
} |
Yes, I think your solution should be free of side effects. |
Uwe, thanks a lot for all your help! |
Hi, Can this extendsall also work for multiple childs who dont know what they extend, but they add content to the defined blocks. AND each childs needs to be parsed locally with their own template and their own variables. Greetz, flexjoly |
…count-deletion-text-to-privacy #5380: 旧WEB予約 プライバシーポリシーに会員情報削除の文言を追記する
Hello,
I assume the following scenario:
I have many template directories, when each contains template.html file. Let's assume these directories have names: directory1, directory2, directory3.
Then we add all these directories using Smarty::addTemplateDir() method in exact above order to template directories list.
I'd like to be able to create templates as below:
{block name="contents"}This is {/block}
{extends file="template.html"}
{block name="contents"}{$smarty.block.parent}the {/block}
{extends file="template.html"}
{block name="contents"}{$smarty.block.parent}test.{/block}
I'd like to get as the result the following text:
This is the test.
Now Smarty triggers error in such scenario, because of recursive template loading.
It could detect that a given directory has been used as template directory for template.html file already and continue searching for template.html file from next template directory in directory chain. It would allow to create dynamically modified templates with simple usage from php code:
$smarty->display('template.html');
This code could be used by something like application plugins.
Maybe you have another solution for described scenario?
Bests, Tomasz
The text was updated successfully, but these errors were encountered: