/ Forside / Teknologi / Udvikling / PHP / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
PHP
#NavnPoint
rfh 3959
natmaden 3372
poul_from 3310
funbreak 2700
stone47 2230
Jin2k 1960
Angband 1743
Bjerner 1249
refi 1185
10  Interkril.. 1146
Templates & content
Fra : Zombie Commando


Dato : 04-06-01 13:07

Greetings,

So I tried out the Smarty PHP class system to generate templates and so far
it works great. I have my .php files witch fetch the various menus, headers
and footers needed for each section but somehow I couldn't figure out how to
plug in the actual content!
The reason I used Smarty (http://www.phpinsider.com/php/code/Smarty/) was to
replace my Perl html::template setup. All my pages are static but I needed
to be able to modify content and layout individualy and independant of each
other.
Here's what one of my .php pages contain:

<?php
require("Smarty.class.php");
$smarty = new Smarty;
$smarty->assign("Content","content here");
$smarty->display("artists.tpl");
?>

The artists.tpl reference displays my entire layout but how do I replace
"content here" with a full block of html and text? The ideal solution would
be to fetch a text file containing this content from another directory and
display it as html.

Can anyone help? I'm sure the answer is obvious but I somehow missed it...


-steph
www.raisinlove.com

"Well its simple, AJ. We're cool and you're not. You should just feel lucky
that we're not pounding your ass by the bike racks after school." - Marian
Try Slaughter on AJ Razor

rezinluv @ gashed.com
webmaster @ mutemag.com
webmaster @ drawnandquarterly.com



 
 
Zombie Commando [rai~ (04-06-2001)
Kommentar
Fra : Zombie Commando [rai~


Dato : 04-06-01 13:34

> The artists.tpl reference displays my entire layout but how do I replace
> "content here" with a full block of html and text? The ideal solution
would
> be to fetch a text file containing this content from another directory and
> display it as html.

By the way, I'd like to call up these different pages in a similar way to
Perl's html::template system, such as:

http://www.website.com/artists.php=artistone
http://www.website.com/artists.php=artistfive
ect..

You know, calling up the basic template and have something in the URL to
specify the content...
Unless there's another or better way?

Thanx alot, I'm having a hellish time with this...

-steph
www.raisinlove.com

"Well its simple, AJ. We're cool and you're not. You should just feel lucky
that we're not pounding your ass by the bike racks after school." - Marian
Try Slaughter on AJ Razor

rezinluv @ gashed.com
webmaster @ mutemag.com
webmaster @ drawnandquarterly.com



Jonas Delfs (04-06-2001)
Kommentar
Fra : Jonas Delfs


Dato : 04-06-01 15:36

"Zombie Commando [raisinlove]" <steph-at-raisinlove-dot-com@spam.com> skrev
i en meddelelse news:9ffv02$3pcvn$1@ID-75711.news.dfncis.de...
> By the way, I'd like to call up these different pages in a similar way to
> Perl's html::template system, such as:
>
> http://www.website.com/artists.php=artistone
> http://www.website.com/artists.php=artistfive
> ect..

I guess you mean http://www.website.com/artists.php?something=artistone ...?
Then $something/$HTTP_GET_VARS['something'] will contain "artistone"...

Otherwise, you have to play a litle with $QUERY_STRING

--
Mvh. Jonas Delfs, http://delfs.dk



Zombie Commando [rai~ (04-06-2001)
Kommentar
Fra : Zombie Commando [rai~


Dato : 04-06-01 15:46

> I guess you mean http://www.website.com/artists.php?something=artistone
....?

heh, yeah that's what I really meant.

> Then $something/$HTTP_GET_VARS['something'] will contain "artistone"...

But, pardon this beginner, where would I include this line? In my .php page
or in my class script file? Also, can "artistone" be a .txt file?

> Otherwise, you have to play a litle with $QUERY_STRING

This is beyond me... I guess it would be easier to explain if you wre
familiar with the code in Smarty (see my initial post).

Thanks!

-steph
www.raisinlove.com

"Well its simple, AJ. We're cool and you're not. You should just feel lucky
that we're not pounding your ass by the bike racks after school." - Marian
Try Slaughter on AJ Razor

rezinluv @ gashed.com
webmaster @ mutemag.com
webmaster @ drawnandquarterly.com



Tyrone Slothrop (04-06-2001)
Kommentar
Fra : Tyrone Slothrop


Dato : 04-06-01 16:57

URL would be http://www.website.com/artists.php?artistone

Call content:
<?php
if ($QUERY_STRING)
{
require ("path/to/" . $QUERY_STRING . ".txt");
}
?>

On Mon, 4 Jun 2001 08:34:29 -0400, "Zombie Commando [raisinlove]"
<steph-at-raisinlove-dot-com@spam.com> wrote:

>> The artists.tpl reference displays my entire layout but how do I replace
>> "content here" with a full block of html and text? The ideal solution
>would
>> be to fetch a text file containing this content from another directory and
>> display it as html.
>
>By the way, I'd like to call up these different pages in a similar way to
>Perl's html::template system, such as:
>
>http://www.website.com/artists.php=artistone
>http://www.website.com/artists.php=artistfive
>ect..
>
>You know, calling up the basic template and have something in the URL to
>specify the content...
>Unless there's another or better way?
>
>Thanx alot, I'm having a hellish time with this...
>
>-steph
>www.raisinlove.com
>
>"Well its simple, AJ. We're cool and you're not. You should just feel lucky
>that we're not pounding your ass by the bike racks after school." - Marian
>Try Slaughter on AJ Razor
>
>rezinluv @ gashed.com
>webmaster @ mutemag.com
>webmaster @ drawnandquarterly.com
>


Zombie Commando [rai~ (04-06-2001)
Kommentar
Fra : Zombie Commando [rai~


Dato : 04-06-01 17:16

> URL would be http://www.website.com/artists.php?artistone
>
> Call content:
> <?php
> if ($QUERY_STRING)
> {
> require ("path/to/" . $QUERY_STRING . ".txt");
> }
> ?>

Ah, excellent...
But, being new to this, I'm not sure where to add this exactly. I mean
somewhere in my php class file, tight? Also, how to I refer to this from the
artists.php page afterwards?

Thanx!

-steph
www.raisinlove.com

"Well its simple, AJ. We're cool and you're not. You should just feel lucky
that we're not pounding your ass by the bike racks after school." - Marian
Try Slaughter on AJ Razor

rezinluv @ gashed.com
webmaster @ mutemag.com
webmaster @ drawnandquarterly.com



Tyrone Slothrop (04-06-2001)
Kommentar
Fra : Tyrone Slothrop


Dato : 04-06-01 19:23

I presume that artists.php is a simple template of a web page and that
the query string represents the name of the file which contains the
content of the page.

You can actually contruct the web completely from templates:

<?
require ("header.html");
require ($QUERY_STRING . ".txt");
require ("footer.html");
?>

Classes and functions really have nothing to do with it. These files
can all be simple HTML, constructed by components. Having common
header and footer files makes life a lot easier when you have to make
changes to a lot of pages at once.

You can also drop a function which makes a query of a database into a
page, and use the template to display the content:

<?
function get_data ($name)
{
$query = "SELECT * FROM table WHERE name = '$name';
$result = mysql_query ($query);
while ($row = mysql_fetch_array ($result))
{
require ("template.php");
}
}
?>
<html>
<body>
<? get_data ($QUERY_STRING); ?>
</body>
</html>

And the template.php file looks like:
Name: <? echo $row ["name"]; ?>
<br>
Address: <? echo $row ["address"]; ?>
<!-- ect. -->

On Mon, 4 Jun 2001 12:16:22 -0400, "Zombie Commando [raisinlove]"
<steph-at-raisinlove-dot-com@spam.com> wrote:

>> URL would be http://www.website.com/artists.php?artistone
>>
>> Call content:
>> <?php
>> if ($QUERY_STRING)
>> {
>> require ("path/to/" . $QUERY_STRING . ".txt");
>> }
>> ?>
>
>Ah, excellent...
>But, being new to this, I'm not sure where to add this exactly. I mean
>somewhere in my php class file, tight? Also, how to I refer to this from the
>artists.php page afterwards?
>
>Thanx!
>
>-steph
>www.raisinlove.com
>
>"Well its simple, AJ. We're cool and you're not. You should just feel lucky
>that we're not pounding your ass by the bike racks after school." - Marian
>Try Slaughter on AJ Razor
>
>rezinluv @ gashed.com
>webmaster @ mutemag.com
>webmaster @ drawnandquarterly.com
>


Zombie Commando [rai~ (04-06-2001)
Kommentar
Fra : Zombie Commando [rai~


Dato : 04-06-01 19:48

Well you make it seem so simple. Why go through all the fuss of templating
systems then?
The website I'm building has 5 sections, each with their own headers and
footers but all using a common main template. Then each of these sections
have their own sub pages with different content.

I realized what I really want is a main file.php to which I would add to
it's url the section name and it's content:

www.website.com/website.php?section=artists+content=intro

(I realize this isn't the proper syntax...).

So it all come sto my site haveing one main template file; 5 sub-tempaltes
for each section hesder; 5 sub-templates for each section footer and a
directory of all the content files.

It's as simple as that. So according to your last suggestion, is there an
easy way to do this? I imagine all the PHP needed for this could simply come
together in the initial website.php file from my example?

If this is a simpler solution, I'll take it. However Smarty seemed to offer
some scripting that allowed the browser to cache the templates...

-steph
www.raisinlove.com

"Well its simple, AJ. We're cool and you're not. You should just feel lucky
that we're not pounding your ass by the bike racks after school." - Marian
Try Slaughter on AJ Razor

rezinluv @ gashed.com
webmaster @ mutemag.com
webmaster @ drawnandquarterly.com
"Tyrone Slothrop" <ts@paranoids.org> wrote in message
news:fjjnhtotrg9e7t7alpi47n1a5ooic8o7b5@4ax.com...
> I presume that artists.php is a simple template of a web page and that
> the query string represents the name of the file which contains the
> content of the page.
>
> You can actually contruct the web completely from templates:
>
> <?
> require ("header.html");
> require ($QUERY_STRING . ".txt");
> require ("footer.html");
> ?>
>
> Classes and functions really have nothing to do with it. These files
> can all be simple HTML, constructed by components. Having common
> header and footer files makes life a lot easier when you have to make
> changes to a lot of pages at once.
>
> You can also drop a function which makes a query of a database into a
> page, and use the template to display the content:
>
> <?
> function get_data ($name)
> {
> $query = "SELECT * FROM table WHERE name = '$name';
> $result = mysql_query ($query);
> while ($row = mysql_fetch_array ($result))
> {
> require ("template.php");
> }
> }
> ?>
> <html>
> <body>
> <? get_data ($QUERY_STRING); ?>
> </body>
> </html>
>
> And the template.php file looks like:
> Name: <? echo $row ["name"]; ?>
> <br>
> Address: <? echo $row ["address"]; ?>
> <!-- ect. -->
>
> On Mon, 4 Jun 2001 12:16:22 -0400, "Zombie Commando [raisinlove]"
> <steph-at-raisinlove-dot-com@spam.com> wrote:
>
> >> URL would be http://www.website.com/artists.php?artistone
> >>
> >> Call content:
> >> <?php
> >> if ($QUERY_STRING)
> >> {
> >> require ("path/to/" . $QUERY_STRING . ".txt");
> >> }
> >> ?>
> >
> >Ah, excellent...
> >But, being new to this, I'm not sure where to add this exactly. I mean
> >somewhere in my php class file, tight? Also, how to I refer to this from
the
> >artists.php page afterwards?
> >
> >Thanx!
> >
> >-steph
> >www.raisinlove.com
> >
> >"Well its simple, AJ. We're cool and you're not. You should just feel
lucky
> >that we're not pounding your ass by the bike racks after school." -
Marian
> >Try Slaughter on AJ Razor
> >
> >rezinluv @ gashed.com
> >webmaster @ mutemag.com
> >webmaster @ drawnandquarterly.com
> >
>



Jacob Bunk Nielsen (04-06-2001)
Kommentar
Fra : Jacob Bunk Nielsen


Dato : 04-06-01 20:25

"Zombie Commando [raisinlove]" <steph-at-raisinlove-dot-com@spam.com> writes:

> www.website.com/website.php?section=artists+content=intro

This is quite simple to make!

You could do something like:

<?php
$header = $section . "/header.php";
$body = $section . "/" . $content . ".php";
$footer = $section . "/footer.php";

if (is_file($header) && is_file($body) && is_file($footer)) {
include($header);
include($body);
include($footer);
}
else if (is_file($header) && is_file($footer)) {
include($header);
include("somedefaultpage.php");
include($footer);
}
else {
print("Whoops - that sucked ...");
}
?>

Then you just have to make a directory for each section and a
header.php and footer.php in each directory.

The syntax for the URL would then be
<http://something.com/somepage.php?section=artists&content=artist5>.
That would make the above code show a page consisting of:

/artists/header.php
/artists/artist5.php
/artists/footer.php

In the artists directory you migth want to make an index.php (or
whatever the index files of your webserver is called) with something
like:

<?php
$url = $HTTP_HOST . "/index.php?section=artists"
header("Location: $url);
?>

I haven't tested the code, so please test it first

.... and since you are posting in a danish newsgroup (where I saw this
article), please use RFC 1855 style qouting, which we are great fans
of in news:dk.edb.internet.webdesign.serverside.php.

RFC 1855 can be found at <http://sunsite.dk/RFC/rfc/rfc1855.html> and
a shorter guide in Danish can be found at
<http://www.usenet.dk/netikette/quote.html>.

--
Jacob
With enough free beer, free speech should come naturally.

Zombie Commando [rai~ (04-06-2001)
Kommentar
Fra : Zombie Commando [rai~


Dato : 04-06-01 20:37

Wow, thanks! I'll try it out and let you know if there are any bugs or
problems...

> ... and since you are posting in a danish newsgroup (where I saw this
> article), please use RFC 1855 style qouting, which we are great fans
> of in news:dk.edb.internet.webdesign.serverside.php.
> RFC 1855 can be found at <http://sunsite.dk/RFC/rfc/rfc1855.html> and
> a shorter guide in Danish can be found at
> <http://www.usenet.dk/netikette/quote.html>.

Yeah, sorry about that. I'm not actually danish, this just happened to be
the newsgroup where I've found the most helpfull people so far :)

-steph
www.raisinlove.com

"Well its simple, AJ. We're cool and you're not. You should just feel lucky
that we're not pounding your ass by the bike racks after school." - Marian
Try Slaughter on AJ Razor

rezinluv @ gashed.com
webmaster @ mutemag.com
webmaster @ drawnandquarterly.com



Jacob Bunk Nielsen (04-06-2001)
Kommentar
Fra : Jacob Bunk Nielsen


Dato : 04-06-01 21:14

"Zombie Commando [raisinlove]" <steph-at-raisinlove-dot-com@spam.com> writes:

> > <http://www.usenet.dk/netikette/quote.html>.
>
> Yeah, sorry about that. I'm not actually danish, this just happened to be
> the newsgroup where I've found the most helpfull people so far :)

We are quite helpful, and actually I haven't seen any requirement that
you have to write in Danish in Danish newsgroups, but we (or at least
I) are (am) quite sensitive about the qouting

Best of luck to you with your project!

--
Jacob
Connection reset by little mexican guy with cable cutters.

Zombie Commando [rai~ (06-06-2001)
Kommentar
Fra : Zombie Commando [rai~


Dato : 06-06-01 22:14

> Best of luck to you with your project!

Hi, here's the update on my project. I hope someone can help, otherwise I
understand I might be asking too much from you. I can offer some graphic
design work in exchange if anyone is interested!

So I used this following code (proposed by Jacob Bunk Nielsen) to generate
all pages:


<?php
$header = $section . "/header.php";
$body = $section . "/" . $content . ".txt";
$footer = $section . "/footer.php";

if (is_file($header) && is_file($body) && is_file($footer)) {
include($header);
include($body);
include($footer);
}
else if (is_file($header) && is_file($footer)) {
include($header);
include("somedefaultpage.php");
include($footer);
}
else {
print("Whoops - that sucked ...");
}
?>


But as I wasn't sure what you intended for me to put in the header.php and
footer.php files, I figured that it should be generic code that:
1. Fetches the (header/footer) template. In my case I would like to link
this to a templates directory. File extension for these templates could be
..txt
2. Assign variables. In the templates I would have {$Title}, {$Submenu}, ...
tags. Here is where I would determine that {$Title}=
"./images/artistheader.gif" for example.

Also, how do I assign a path to where the script will fetch the content
files? In my case I dont want the actual content to be in each section
sub-directory. I would rather have all content in one directory called
"content".

Based on what has been proposed to me and what I need next, can you help?
Thanx!

-steph
www.raisinlove.com

"Well its simple, AJ. We're cool and you're not. You should just feel lucky
that we're not pounding your ass by the bike racks after school." - Marian
Try Slaughter on AJ Razor

rezinluv @ gashed.com
webmaster @ mutemag.com
webmaster @ drawnandquarterly.com



Jacob Bunk Nielsen (06-06-2001)
Kommentar
Fra : Jacob Bunk Nielsen


Dato : 06-06-01 23:39

"Zombie Commando [raisinlove]" <steph-at-raisinlove-dot-com@spam.com> writes:

> Hi, here's the update on my project. I hope someone can help, otherwise I
> understand I might be asking too much from you. I can offer some graphic
> design work in exchange if anyone is interested!

I already answered the email you sent my way!

--
Jacob
The future will be better tomorrow.

Olicom Crossfire 8400 switch til salg, send et bud ...

Søg
Reklame
Statistik
Spørgsmål : 177560
Tips : 31968
Nyheder : 719565
Indlæg : 6408943
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste