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

no tpl file, just 1 php file

 
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
twopeak
Smarty Rookie


Joined: 09 Jun 2003
Posts: 12

PostPosted: Sun Sep 07, 2003 2:41 pm    Post subject: no tpl file, just 1 php file Reply with quote

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
View user's profile Send private message
wvdploeg
Smarty Rookie


Joined: 05 Aug 2003
Posts: 19

PostPosted: Sun Sep 07, 2003 9:05 pm    Post subject: Re: no tpl file, just 1 php file Reply with quote

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


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Sep 07, 2003 10:18 pm    Post subject: Reply with quote

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! Smile
Back to top
View user's profile Send private message
twopeak
Smarty Rookie


Joined: 09 Jun 2003
Posts: 12

PostPosted: Mon Sep 08, 2003 8:30 am    Post subject: Reply with quote

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


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Sep 08, 2003 9:06 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Sep 08, 2003 12:39 pm    Post subject: Reply with quote

I think your one file idea is madness in this case. Wink 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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Sep 08, 2003 12:49 pm    Post subject: Reply with quote

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 Smile )
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Sep 08, 2003 1:02 pm    Post subject: Reply with quote

<boots buys messju a coffee>
Back to top
View user's profile Send private message
twopeak
Smarty Rookie


Joined: 09 Jun 2003
Posts: 12

PostPosted: Thu Sep 11, 2003 1:35 pm    Post subject: Reply with quote

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
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