|
-
Jan 29th, 2003, 09:28 PM
#1
Thread Starter
Hyperactive Member
Template variable question...
Im trying to get the title of the page to be read from my database. What i have done so far is tryed this. I made the table and entered the data into mySQL. Then i put a variable in the <title> tag in the template. And i defined the veriable in the php index part. But when i load the page it only shows the variable not the text in the database. Can you help me fix this?
-
Jan 29th, 2003, 10:49 PM
#2
Stuck in the 80s
Can you supply some code? From your description, I'm not exactly sure what you're doing.
-
Jan 30th, 2003, 05:38 PM
#3
Thread Starter
Hyperactive Member
well i have my template,
Code:
<html>
<head>
<title>$title</title>
</head>
<body>
$content
</body>
</html>
and in my php file i have this...
$title = "test"
$content = "content"
and nothing happens
-
Jan 30th, 2003, 06:05 PM
#4
The $title needs to be in PHP tags..... otherwise it doesn't get parsed out by PHP and ends up getting sent right to the browser try this:
PHP Code:
<html>
<head>
<title><?php echo $title; ?>
</title>
</head>
<body>
<?php echo content; ?>
</body>
</html>
-
Jan 30th, 2003, 06:09 PM
#5
Thread Starter
Hyperactive Member
but i have it running through php like this...
PHP Code:
<?
include_once("template.tpl");
$title = "test"
$content = "content"
?>
do i still need to do that php in the template?
-
Jan 30th, 2003, 06:10 PM
#6
Stuck in the 80s
Originally posted by Muk108
but i have it running through php like this...
PHP Code:
<?
include_once("template.tpl");
$title = "test"
$content = "content"
?>
do i still need to do that php in the template?
Yes. PHP outputs included files to the browser as is until it reaches a PHP tag. Then it starts parsing it as PHP code until it finds a closing tag.
So you do need them around $title:
Code:
<title><?php echo $title; ?></title>
-
Jan 30th, 2003, 06:41 PM
#7
Thread Starter
Hyperactive Member
What is they way you see templates used that have the {veriable} and they dont have the <? ?> around it? Im trying to do that so i dont have to have multiple includes. Can you ehlp me with this?
-
Jan 30th, 2003, 09:42 PM
#8
Stuck in the 80s
-
Jan 30th, 2003, 09:56 PM
#9
Thread Starter
Hyperactive Member
i think it has something to do with a template engine but im nto sure.
-
Jan 30th, 2003, 10:41 PM
#10
Mind if I ask a question here... what is a .tpl template?
-
Jan 30th, 2003, 11:24 PM
#11
Stuck in the 80s
Originally posted by Muk108
i think it has something to do with a template engine but im nto sure.
I have no idea what you're talking about anymore.
-
Jan 31st, 2003, 06:53 AM
#12
Thread Starter
Hyperactive Member
i read somewhere that things like phpBB use template engines. and then somewhere i saw that a template engine is the thing that lets you use variables in your template so you dont have to use php. now i was wondering if you know how to do this? a .tpl file is just another way of nameing the template file. its still raw text just with a different extention like .php or .html etc.
-
Jan 31st, 2003, 09:53 AM
#13
Conquistador
vBulletin also uses a "template engine".
Each individual part of a page is in a template.
In the php file it is evaluated, so that any variables inside that template become normal text for the string e.g.
$newsbits = eval(gettemplate("home_newsbit));
or something
then vBB has a main template for each page which encompasses all the evaluated templates and builds it for output.
That's my understanding of the vbb one at least, perhaps John - the old admin could shed some light on it, as he's on the vbb project.
-
Jan 31st, 2003, 10:27 AM
#14
He's using the SMARTY template engine.... unfortunatly that's something outside my knowledge. If you want to know more about it, check out http://www.xoops.org -- their system uses the SMARTY templating system and they have links and people that might be more use.
-
Jan 31st, 2003, 03:20 PM
#15
Thread Starter
Hyperactive Member
well, would you recommend any other "template engine" that is good because im not understanding this smarty one.
-
Jan 31st, 2003, 03:24 PM
#16
Sorry... the only kind of templating I've ever done has been building my own....
-
Feb 3rd, 2003, 10:50 PM
#17
New Member
Originally posted by Muk108
but i have it running through php like this...
PHP Code:
<?
include_once("template.tpl");
$title = "test"
$content = "content"
?>
do i still need to do that php in the template?
shouldn't you define the variables before you include the template?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|