There sure are a lot of advantages when the designer and the programmer are two (or more) different people, but I'm both programmer and designer. I'm considering using Smarty templates because it produces cleaner code and does have some nice features like built-in functions for formatting data and layout. However, I'm going to need to use different languages (English, Dutch, ...) and I don't see a good way to implement this using Smarty: using several templates would be bothersome because the HTML would have to be edited twice in case of changes. Using seperate variables for each sentence might do the trick, but then again that would also be easier without Smarty because I could simply use a translate("Text") function or something.
Does anyone have any ideas?
What are the downsides of using Smarty Templates?
Moderator: General Moderators
Generally the downside is speed if using smarty...nothing else if you ask me.
You can easily implment different languages using config files
Other than that smarty have really good build in functions...easily extendable...good support.
I like it...speed is no such concern for me.
You can easily implment different languages using config files
Other than that smarty have really good build in functions...easily extendable...good support.
I like it...speed is no such concern for me.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
/quick pitch for template lite...
There are numeroud ways to do what you want using a template engine. Right now I have a site that uses a template system that literally uses three templates for a site that has a possible 40 pages. As for language changes, you can either set up your language in a database, use language text files (like arrays, etc) or use Smarty/Template lite to include a particular template based on a selected var value. There are a lot of options.
There are numeroud ways to do what you want using a template engine. Right now I have a site that uses a template system that literally uses three templates for a site that has a possible 40 pages. As for language changes, you can either set up your language in a database, use language text files (like arrays, etc) or use Smarty/Template lite to include a particular template based on a selected var value. There are a lot of options.
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
Your best bet is to use language files. These files are basically PHP files you include into the PHP program that is executing.
An example...
The $_SESSION['language'] variable is set to english. So the english.inc file is loaded from the language directory. Inside the english.inc you have something like this...
And the mypage.tpl could look something like...
That's one of many ways to have language specific pages using a template engine.
An example...
Code: Select all
<?php
session_start();
//define ('TEMPLATE_DIR', "backends/Smarty/libs/");
define ('TEMPLATE_LITE_DIR', "backends/template_lite/src/");
// Define the template class location:
//define('TEMPLATE_CLASS', TEMPLATE_DIR . "Smarty.class.php");
define('TEMPLATE_CLASS', TEMPLATE_LITE_DIR . "class.template.php");
require_once (TEMPLATE_CLASS);
$template_object = new Template_Lite;
//$template_object = new Smarty;
$template_object->template_dir = "./templates/";
$template_object->compile_dir = "./templates_c/";
include ("language/" . $_SESSION['language'] . ".inc");
$template_object->display("mypage.tpl");
?>Code: Select all
<?php
$template_object->assign("title", "This is my page title");
$template_object->assign("name", "Please enter your name");
$template_object->assign("submit_button", "Click to Submit");
?>Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>{$title}</title>
</head>
<body>
<table>
<tr>
<td>
<form action="name.php" method="post">
{$name} <input type="text" name="name" width="30" size="40" value=""><br>
<input type="Submit" value=" {$submit_button} ">
</form>
</td>
</tr>
</table>
</body>
</html>That's one of many ways to have language specific pages using a template engine.