Welcome to WebmasterWorld Guest from 54.160.163.163

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Smarty: Using Nested Templates

Is it possible?

     

cosmoyoda

4:42 pm on Oct 21, 2008 (gmt 0)

5+ Year Member



I've come across a few problems with Smarty lately. I believe it is not a big issue, or maybe just caused by my relative lack of knowledge using this smart PHP template engine.

My problem is I need to start using Nested Templates. For Adobe Dreamweaver users this term might be familiar to you. I love nested templates because they let me create One Universal Template (the Master Template), containing the header and footer of the entire site, and in between the content wrapper. That way any template I create that inherits the master template will already have the headers and footers wrapped around it.

I am tired of having to call {include_php file='header.php'} on the top of every template and {include_php file='footer.php'} after my template content. This possible nested template feature could certainly speed things up a bit and make my code cleaner and easier to manipulate.

So I was wondering if there is such "Nested Template" in Smarty and if not what ideas can you guys give me so I can implement it myself. Any good strategy, plugins or hidden Smarty features that I might not be aware of that you guys would like to share in this thread would be kindly appreciated.

Thanks for reading.

Best regards,

coopster

4:52 pm on Oct 24, 2008 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Are you aware of the PHP auto_prepend_file and auto_append_file [php.net] configuration directives? They may be of interest to you.

cosmoyoda

8:09 pm on Oct 24, 2008 (gmt 0)

5+ Year Member



coopster, no I was not aware of the PHP auto_prepend_file and auto_append_file. However I did some research on these functions and didn't find much information available on the web. Got lucky and discovered that what it does is to automatically include files before and after the code of a PHP script. Am I right?

That, of course, is wonderful! I did not know there was such feature in PHP and it can certainly be helpful right now. Thank you!

coopster

11:01 pm on Oct 24, 2008 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Yes, you are correct. auto_prepend_file allows you to automatically prepend a file to each request, it gets included before your script. append is included after your script.

One tedious little technical note though ... they are not functions, they are configuration directives [php.net]. They are of type

PHP_INI_PERDIR
which means the entry can be set in php.ini, .htaccess or httpd.conf. If you are using a shared hosting provider, you'll have to see if they will allow you to use those directives.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month