Page 1 of 1
What are the downsides of using Smarty Templates?
Posted: Fri Aug 04, 2006 3:34 am
by nutkenz
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?
Posted: Fri Aug 04, 2006 3:40 am
by Jenk
Store your content in the different languages you support in your database, and retrieve the language the user has chosen to view.
That way no multiple templates.
Posted: Fri Aug 04, 2006 3:41 am
by jmut
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.
Posted: Fri Aug 04, 2006 10:05 am
by Luke
plus you can speed things up w/caching
Posted: Fri Aug 04, 2006 10:21 am
by RobertGonzalez
/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.
Posted: Fri Aug 04, 2006 12:12 pm
by AKA Panama Jack
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...
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");
?>
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...
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");
?>
And the mypage.tpl could look something like...
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.