473,670 Members | 2,499 Online
Bytes | Software Development & Data Engineering Community
+ 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 3524
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=valu e) { ?> this HTML <?php } else if ($Variable=valu e) { ?> 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_templat es(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*****@hotmai l.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.andyhsoftwa re.co.uk/space>
Jul 17 '05 #4
On Thu, 11 Mar 2004 18:54:33 GMT, MrPlow <de********@hot mail.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.andyhsoftwa re.co.uk/space>
Jul 17 '05 #5
Andy Hassall wrote:
On Thu, 11 Mar 2004 18:54:33 GMT, MrPlow <de********@hot mail.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*****@hotmai l.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*****@hotmai l.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.c om/groups?threadm= c17ndg%24l3t%24 1%40newsreader. mailgate.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
2079
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 for really ugly code. Would a templating engine solve that? Does anyone have any suggestions about which one to use?
3
1431
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 Albatross, and it's nice, though it would be nicer still if it had proper support for 'code tags' ala <? ?>. --
7
1254
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 XML/HTML) I don't need a framework (already have it), but just simple templating. The syntax I had in mind is something like that:
2
1570
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% or <MYusername/> would be replaced by the value. basically what the perl cookbook uses in a few examples iirc. however more and more we have to deal with more complex data. variable length lists of data. say for example a list of new products...
1
1279
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 can edit HTML files without having to get involved with VS at all. http://www.codeproject.com/aspnet/page_templates.asp - this seems to be the best so far, if I can modify the code to use an external template file. Are there any other...
18
4961
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 overwhelmed by the plethora of different frameworks, templating engines, HTML generation tools etc that exist. After some thought I decided to leave the various frameworks aside for the
7
1616
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 doubt I am using it to its full extent but I want to learn more about, and compare and contrast, frameworks versus IDE versus templating systems and MOST IMPORTANTLY learn what is going to save me time. I know technically the IDE is the tool in...
10
1706
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 constructs with the HTML document itself. An opposite approach to this form of dynamic HTML production is called push-style templating, as coined by Terence Parr:
0
8468
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8901
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4209
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4390
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2799
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 we have to send another system
2
1792
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.