Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Auto extend templates with the same name

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
tsurt
Smarty n00b


Joined: 17 Oct 2016
Posts: 1

PostPosted: Mon Oct 17, 2016 7:52 am    Post subject: Auto extend templates with the same name Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Oct 17, 2016 2:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Oct 23, 2016 9:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP