473,466 Members | 1,430 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP Templating Systems and Conditional HTML

Which of the popular templating systems (e.g. PHLib, FastTemplate,
Smarty) allow you to setup conditions in your templates, for example:

<-- IF Variable=value -->
this HTML
<-- ELSEIF Variable=value -->
this HTML
<-- ENDIF Variable=value -->

--Bruce

Jul 17 '05 #1
7 3514
Bruce wrote:
Which of the popular templating systems (e.g. PHLib, FastTemplate,
Smarty) allow you to setup conditions in your templates, for example:
php does this fine on it's own

<?php IF ($Variable=value) { ?> this HTML <?php } else if ($Variable=value) { ?> this HTML

<?php } ?>
Jul 17 '05 #2
Bruce wrote:
Which of the popular templating systems (e.g. PHLib, FastTemplate,
Smarty) allow you to setup conditions in your templates, for example:

<-- IF Variable=value -->
this HTML
<-- ELSEIF Variable=value -->
this HTML
<-- ENDIF Variable=value -->

--Bruce


IMO the main purpose of using templates is to separate your logic from
your layout.

Having said that, I know that FastTemplate, or DTemplate (my own
template class which is almost functionaly identical to FT) can
accomplish what you want using their dynamic block functionality.

example using DTemplate:

template.tpl:

<DTDYN:block1>
block1 html
</DTDYN:block1>
<DTDYN:block2>
block2 html
</DTDYN:block2>

template.php:

<?php
$tpl = new DTemplate('path/to/tpl/file');
$tpl->define_templates(array('body' => 'template.tpl'));
$tpl->define_dynamic('block1', 'body');
$tpl->define_dynamic('block2', 'body');
if ($var = true)
{
$tpl->clear_dynamic('block1');
}
else {
$tpl->clear_dynamic('block2');
}
//process template stuff and print
?>

dtemplate doc: http://desolatewaste.com/projects/dtemplate/readme.htm
fasttemplate doc: http://www.thewebmasters.net/php/FastTemplate.phtml
Jul 17 '05 #3
On Thu, 11 Mar 2004 13:22:34 GMT, Bruce <br*****@hotmail.com> wrote:
Which of the popular templating systems (e.g. PHLib, FastTemplate,
Smarty) allow you to setup conditions in your templates, for example:

<-- IF Variable=value -->
this HTML
<-- ELSEIF Variable=value -->
this HTML
<-- ENDIF Variable=value -->


Smarty certainly does.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #4
On Thu, 11 Mar 2004 18:54:33 GMT, MrPlow <de********@hotmail.com> wrote:
IMO the main purpose of using templates is to separate your logic from
your layout.


But layout itself can need 'logic' - depending on how you define 'logic'.

Templates IMO are to separate your 'data logic' from your 'presentation logic'
- for presentation beyond the trivial 'loop round an array and print a table
cell per entry' having some sort of basic code support in the template can be
useful, else you end up pushing presentation information into your 'data
logic', where it doesn't really belong.

Depends on your view of things, of course, which is why there are a million
and one templating systems that each work according to the opinion of their
author on this issue. :-)

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #5
Andy Hassall wrote:
On Thu, 11 Mar 2004 18:54:33 GMT, MrPlow <de********@hotmail.com> wrote:

IMO the main purpose of using templates is to separate your logic from
your layout.

But layout itself can need 'logic' - depending on how you define 'logic'.

Templates IMO are to separate your 'data logic' from your 'presentation logic'
- for presentation beyond the trivial 'loop round an array and print a table
cell per entry' having some sort of basic code support in the template can be
useful,


You've got me there. I considered not including dynamic blocks in my
class at all, but even I used them constantly when I was using
FastTemplate, so I can't deny that it would probably be even more useful
to have extra logical controls in the templates, just haven't tried it.

My goal was to have templates that could be edited by people who know
how to use Dreamweaver, but have never programmed anything like PHP before.
else you end up pushing presentation information into your 'data
logic', where it doesn't really belong.

Not necessarily. I've come up with a bunch of ways to separate them...
I think I'm nearing a method that I wouldn't mind using more than once
too! :P
Depends on your view of things, of course, which is why there are a million
and one templating systems that each work according to the opinion of their
author on this issue. :-)


Yep.
Jul 17 '05 #6
On Thu, 11 Mar 2004 13:22:34 GMT, Bruce <br*****@hotmail.com> wrote:
Which of the popular templating systems (e.g. PHLib, FastTemplate,
Smarty) allow you to setup conditions in your templates, for example:

<-- IF Variable=value -->
this HTML
<-- ELSEIF Variable=value -->
this HTML
<-- ENDIF Variable=value -->

--Bruce


My personal redevlopment of Fasttemplate does. The templates also
validate as HTML, because they use <!-- -->

See my signature,

Jochen

--
Jochen Daum - Cabletalk Group Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #7
Bruce <br*****@hotmail.com> wrote in message news:<dv********************************@4ax.com>. ..
Which of the popular templating systems (e.g. PHLib, FastTemplate,
Smarty) allow you to setup conditions in your templates, for example:

<-- IF Variable=value -->
this HTML
<-- ELSEIF Variable=value -->
this HTML
<-- ENDIF Variable=value -->


The most popular template system is PHP itself. This topic and the
suggestions are often disputed at least bye someone. For more info,
see the recent discussions on this topic
<http://groups.google.com/groups?threadm=c17ndg%24l3t%241%40newsreader.mailg ate.org>

The important thing here is people often change their styles and so
their template system.

<trivia>When Jochen and I had a discussion about template system
about a year ago, he was backing Smarty. But, now he came up with
another system :-)</trivia>

--
"I don't believe in the God who doesn't give me food, but shows me
heaven!"--Swami Vivekanandha
Email: rrjanbiah-at-Y!com
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Leif K-Brooks | last post by:
I'm planning to start on a fairly large web application, most likely using mod_python. I recently wrote a fairly small (but real-world useful) web app with it, and all of those req.write()s made...
3
by: Chris Stiles | last post by:
Hi -- Does anyone have any recommendations for simple web templating systems for python that also allow execution of python code within the the templates themselves ? So far I'm using...
7
by: Ksenia Marasanova | last post by:
Hi, I am looking for fast, simple templating system that will allow me to do the following: - embed Python code (or some templating code) in the template - generate text output (not only...
2
by: lloyd christopher | last post by:
im developing a template based web application in perl and need some guidance. currently its all pretty simple stuff, we tell the designers place holders to use and then &username; or %USERNAME%...
1
by: Chris Ashley | last post by:
I have been looking into templating systems these past few days, but nothing seems to suit my purpose. I want to achieve complete separation of code and design in a templating system, so a designer...
18
by: pkassianidis | last post by:
Hello everybody, I am in the process of writing my very first web application in Python, and I need a way to generate dynamic HTML pages with data from a database. I have to say I am...
7
by: Paul | last post by:
I have been coding apps with PHP for several years. But I am getting more involved in larger and more complicated PHP applications and want to use best practices. I use Eclipse's PHP IDE. I...
10
by: Terrence Brannon | last post by:
Hello, The most common way of dynamically producing HTML is via template engines like genshi, cheetah, makotemplates, etc. These engines are 'inline' --- they intersperse programming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.