English 中文(简体)
Alternatives to Smarty for separating presentation from code in php?
原标题:

I m currently using the Smarty templating system for our production site, but am curious how much of a performance hit I m taking by using this templating engine. Are there faster alternatives? Is there a way to code so I may not have to use such a templating system? Thank you!

最佳回答

You don t need an external templating engine to separate code from presentation, you just need logic for that. PHP itself is perfectly fine as a template engine -- just don t mix PHP code and HTML. Template engines are just easier to learn for a non programmer web designer.

问题回答

The obvious answer - just use PHP. Many argue that it IS a templating language, although I prefer to use Smarty.

Smarty forces PHP developers to separate business logic, database calls, etc from the presentation. However, a disciplined PHP developer can use PHP as a templating language and keep the presentation separate.

Also you can use XSL transformations to separate logic from presentation. XSLT-transformer receives XML tree and generates HTML output, using XSLT transformations to produce presentation.

But XSLT is quite difficult for studying and demands knowledge of XML and XPath. I have been using Smarty in my recent projects, but my current project is build on XSLT templates, so I had to learn XSLT. It seems more complicated to me, that Smarty and its ancestor FastTemplate. However, XSLT is another way to separate logic from presenatation.

Advantage of XML & XSLT is that these technologies are used with different languages, not only with PHP.

Besides there is one more template engine - PHP template engine. It is default template engine for Drupal CMS. I m not Drupal expert, so I can say nothing about it. However it uses PHP syntax, so it is quite simple to learn.

You can read about XSLT here.

I hope my answer will be useful for you.

You can try Psttt! templating engine for php

full source code here http://github.com/givanz/psttt





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签