RE: [SMARTY] Conditionally include file based on document location
| From: | Josh Johnson | Date: | Thu, 19 Sep 2002 12:15:06 +0000 |
| Subject: | RE: [SMARTY] Conditionally include file based on document location | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5999@lists.php.net to get a copy of this message | ||
Eric:
Does apple know about this? :)
One way to do it would be to tell the template engine what page it's on
inside of each page, like this:
/index.html:
<? $page = "index";
... other sutff ...
include(smarty stuff...);
$smarty = new Smarty;
$smarty->assign("this_page", $page);
$smarty->display("template_for_this_page.tpl");
?>
Then in
"template_for_this_page.tpl":
{include file=header.tpl}
Then in header.tpl (header.tpl would be a shared file amoungst all of
the templates):
{if $page == "quicktime"}
{include file="quicktime_header_thing.tpl"}
{elseif $page == "index"}
{include file="index_header_thing.tpl"}
{... etc ...}
{/if}
There are a few variations on that idea (some that I'm sure are more
efficient and some that depend on how you've got things set up), but I
think that illustrates what I mean.
-- Josh
-----Original Message-----
From: Eric C. Pollitt [mailto:eric@globalhemp.com]
Sent: Tuesday, September 17, 2002 4:36 PM
To: smarty-general@lists.php.net
Subject: [SMARTY] Conditionally include file based on document location
I would like to know how to conditionally included a file based on the
document location.
The purpose is for placement of location-specific navigation menus.
I'm not interested in DHTML hierarchical drop-down menus, rather
inserting
ready made HTML files using perhaps (?) DOCUMENT_URI (?) and error
checking
logic.
------------------------------------------------------------------------
----
EXAMPLE
If DOCUMENT_URI is "/" (home) then the following file included:
URL: <http://www.globalhemp.com/includes/apple.html>
If DOCUMENT_URI is "/quicktime/" then the following file included:
URL: <http://www.globalhemp.com/includes/quicktime.html>
If DOCUMENT_URI is "/quicktime/download/" then the following file
included:
URL: <http://www.globalhemp.com/includes/quicktime_download.html>
------------------------------------------------------------------------
----
The error checking logic would be for child directories that don't have
their own include file and thus would use a parent directory include
file.
If a parent directory file doesn't exist, it would include the top-level
(home) include file.
The closest PHP example that I have found thus far follows:
------------------------------------------------------------------------
----
[INCOMPLETE] PHP CONDITIONAL INCLUDE EXAMPLE
Extracted from: <http://www.jwweb.com/20010629.html>
<?php
if ($location == "quicktime") {
include("quicktime.inc");
if ($location == "quicktime/download") {
include("download.inc");
} else {
include("home.inc");
}
?>
------------------------------------------------------------------------
----
THANKS!
Eric C. Pollitt, Founder
401 E. Illinois Ave.
Peoria, IL 61603
Global Hemp - Portal to the hemp community
http://www.globalhemp.com/
Create like a god. Command like a king. Work like a slave!
-- Constantin Brancusi
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php