|
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 |
tsurt Smarty n00b
Joined: 17 Oct 2016 Posts: 1
|
Posted: Mon Oct 17, 2016 7:52 am Post subject: Auto extend templates with the same name |
|
|
Hello everybody,
i have this folder-structure:
Code: | --templates
--templates-->index.tpl
--templates-->head.tpl
--templates-->header.tpl
--templates-->footer.tpl
--modules
----mod1
------templates
------templates-->head.tpl
------templates-->footer.tpl
------templates-->mod1_custom.tpl |
In my index.php i do:
Code: | $smarty->display('index.tpl'); |
Example: In the standard head.tpl there ist a block
Code: | {block name="head_javascript"}{block} |
and my module head.tpl looks like:
Code: | {extends file="parent:head.tpl"}
{block name="head_javascript"}
{$smarty.block.parent}
<link href="/modules/meldehistory/css/meldehistory.css" rel="stylesheet" type="text/css">
{/block}
{block name="head_css"}
{$smarty.block.parent}
<link href="/modules/meldehistory/css/meldehistory.css" rel="stylesheet" type="text/css">
{/block} |
If there is a modul folder, i add the template_dir to smarty. Now i want that this head.tpl extends the standart head.tpl. Is there an easy way to obtain this, or is this the wrong way to add modules to an app with smarty?
Greetings |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Oct 17, 2016 2:59 pm Post subject: |
|
|
My opinion, you've got it backwards.
You should INCLUDE, not EXTEND your head.tpl.
I.e.
1. article.tpl(block "title", block "content", block "keywords") extends index.tpl(block "title", block "content", block "keywords").
2. pager.tpl(block "title", block "page-content", block "keywords", block "pager") extends pager-index.tpl(block "content" containing the block "page-content" and 2x block "pager") extends index.tpl(block "title", block "content", block "keywords")
In turn, the index.tpl include certain blocks that are making the frame of the page. Menus, header, footer, user's information block.
A more in-code example of such approach can be seen in
http://www.smarty.net/forums/viewtopic.php?t=25486 |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Oct 23, 2016 9:57 pm Post subject: |
|
|
In the demo folder is in the plugins folder the resource extendsall.
It does scan the template_dir folders and extends all template files of a given name.
Add demo plugins
Code: |
$smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
|
Remove all extends tags in the module template files
Replace {extends file="head.tpl"} with {extends file="extendsall:head.tpl"} |
|
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
|