Jump to content

Template?


Recommended Posts

I want to use a template for my website. A guy on another forum told me I had to use a template parser like Templatepower or Smarty.

 

Isn't there an easier way, just to implent a code or something?

 

I only want one template file and connect that one to a PHP-file with content. Then be able to change the content to content from another PHP-file when I click on a link on my site. No more functions needed.

 

 

Link to comment
Share on other sites

if you split your webpage in half and include the into the script files you will only have 2 files to worry about for the whole website

Header.php:

<html>
<head>
header info here.
</head>
<body>
<div><?php

Footer.php :
?>
</div>
</body>
</html>

 

 

Link to comment
Share on other sites

How should your template looks like?

My templates are built like that:

<html>
<head>
<title>{{title}}</title>
</head>

<body>
{{content}}
</body>
</html>

Let's say that content is in the file template.tpl

Now index.php:

<?php
$file = '';
if (file_exists('template.tpl') === true && ($size = filesize('template.tpl')) > 0) {
	$fp = fopen('template.tpl', 'r');
	$file = fread($fp, $size);
	fclose($fp);
}

$var_titles[0] = '{{title}}';
$var_titles[1] = '{{content}}';
$var_replace[0] = 'Test';
$var_replace[1] = 'The content of this file is near';

$file = str_replace($var_titles, $var_replace, $file);
echo $file;
?>

Link to comment
Share on other sites

I tried this but it doesn't seems to work:

 

 

index.php:

 

<?php

$title = "The title";

$content = "blablabla";

 

include ('template/main.php');

?>

 

template/main.php:

 

<html>

<head>

<title><?php echo $title; ?></title>

 

</head>

<body>

 

<?php echo $content; ?>

 

</body>

</html>

 

You had this right... you just forgot your quotation marks.

 

So your code should look like this:

 

index.php:

<?php
$title = "The title";
$content = "blablabla";

include ('template/main.php');
?>

template/main.php:

<html>
<head>
<title><?php echo "$title"; ?></title>

</head>
<body>

<?php echo "$content"; ?>

</body>
</html>

 

Should work fine now!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.