View previous topic :: View next topic |
Author |
Message |
twopeak Smarty Rookie
Joined: 09 Jun 2003 Posts: 12
|
Posted: Sun Sep 07, 2003 2:41 pm Post subject: no tpl file, just 1 php file |
|
|
Hello
I have several files that are written in html, they are completely static, and do not require php.
But, these documents should have the header and footer I use for the whole site!
Or on other pages there's so little php code, it's overkill to create 2 documents...
So I would like to have 1 file, that gets read like a template.
(using ssi to include files is not really an option, as the header must go through smarty...)
any ideas on how to do this? |
|
Back to top |
|
wvdploeg Smarty Rookie
Joined: 05 Aug 2003 Posts: 19
|
Posted: Sun Sep 07, 2003 9:05 pm Post subject: Re: no tpl file, just 1 php file |
|
|
Just one question. Why <b>must</b> the header go through smarty ?
What 'problem' do you want to solve in the header, you can't solve by PHP or SSI ? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun Sep 07, 2003 10:18 pm Post subject: |
|
|
There are several things you can do. First, you can use (cough) frames.
Second, if you are using Smarty anyhow, you can create a basic template like:
[php:1:6af572fc35]$smarty->assign('static_file', 'file.html');
$smarty->display('standard.tpl');[/php:1:6af572fc35]
Code: | {* standard.tpl *}
{include file="header.tpl"}
{fetch file=$static_file}
{include file="footer.tpl"} |
If your header and/or footer are not themselves static, then your final page is not static even if it contains static content. If you use caching, you can still get good performance, though. On the other hand, if your headers and footers ARE static, then you can use the above technique to generate the pages you need and just save the generated content as a static page (ie. instead of display(), use fetch() and write the results to disk).
wvdploeg wrote: | What 'problem' do you want to solve in the header, you can't solve by PHP or SSI ? | hmmm. Sounds like you don't think Smarty has its uses! |
|
Back to top |
|
twopeak Smarty Rookie
Joined: 09 Jun 2003 Posts: 12
|
Posted: Mon Sep 08, 2003 8:30 am Post subject: |
|
|
the header file, contains several smarty variables (like title and variable link tags, they contain information from the url)
so it has to pass through smarty!
The footer file might be skipped, as it's really static.
If I use frames, it doesn't really solve my problem: I would have to create 2 files just to parse the header (the frames def. and a php file) then a third one with the normal html content and a fourth one for the footer (this one coule be skipped)
The last solution still includes 2 files: the php file that calls in the basic template, and the static file...
It's really nothing much of a big problem, but I think it would be handy if I could make a string with the heredoc syntax (<<<) and say this is my template, and the same php file would parse & output it... |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Sep 08, 2003 9:06 am Post subject: |
|
|
twopeak wrote: | It's really nothing much of a big problem, but I think it would be handy if I could make a string with the heredoc syntax (<<<) and say this is my template, and the same php file would parse & output it... |
hmm, you can use an auto-prepend_file, maybe sth. like:
<?php
... init smarty...
$smarty->display('header.tpl');
readfile(__FILE__);
$smarty->display('footer.tpl');
exit; /* important, your template would be processed a second-time otherwise */
?>
just an idea
messju |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Sep 08, 2003 12:39 pm Post subject: |
|
|
I think your one file idea is madness in this case. It doesn't really buy you much, and down the road when you want to edit your header/footer, it will be much harder to deal with several single files since things aren't separated. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Sep 08, 2003 12:49 pm Post subject: |
|
|
messju wrote: |
<?php
... init smarty...
$smarty->display('header.tpl');
readfile(__FILE__); |
shit, of course it's not __FILE__ (which would be the prepend-file), but $_SERVER['SCRIPT_FILENAME'] or so.
Quote: | $smarty->display('footer.tpl');
exit; /* important, your template would be processed a second-time otherwise */
?> |
(memo to self: don't post on mondays before 2pm ) |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Sep 08, 2003 1:02 pm Post subject: |
|
|
<boots buys messju a coffee> |
|
Back to top |
|
twopeak Smarty Rookie
Joined: 09 Jun 2003 Posts: 12
|
Posted: Thu Sep 11, 2003 1:35 pm Post subject: |
|
|
so I'm the only one with these problems?
I thought (hoped) more people would think like me, and that it would be considered as a feature of a next version...
anyway, thanks for the help, but I think I'll stick to to 'normal' because I'll need 2 files anyway... |
|
Back to top |
|
|