Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Sean Coates' Blog:
PHP as a templating language
May 15, 2012 @ 15:58:37

In this new post to his blog Sean Coates talks about PHP as a templating language and why he (and Gimmebar) have decided to go another, more frontend-based direction.

For many years, I was a supporter of using PHP as a templating language to render HTML. However, I really don’t buy into the idea of adding an additional abstraction layer on top of PHP, such as Smarty (and many others). In the past year or so, I’ve come to the realization that even PHP itself is no longer ideally suited to function as the templating engine of current web applications - at least not as the primary templating engine for such apps.

His reasoning is pretty simple - more and more web applications are becoming less and less server-driven. When building applications (and APIs) you don't know how the data will be consumed, so your frontend has to be agnostic. So, what's his current alternative of choice? The Mustache templating framework provides a simple way to create reusable templates (along with the compatible Handlebars Javascript library).

tagged: templating language smarty mustache handlebars javascript api

Link:

Smashing Magazine:
Getting Started With PHP Templating
Oct 18, 2011 @ 14:15:49

On the Smashing Magazine site today there's a new post introducing you to templating in PHP applications. They cover both the creation of a simple, custom templating library as well as using a more widely known too - Twig.

In this article, we’ll cover how to separate the view of your PHP application from its other components. We’ll look at why using such an architecture is useful and what tools we can use to accomplish this. [...] To fully benefit from this article, you should already know how to write and run your own PHP scripts on a Web server (i.e. using Apache).

They start with the very basics of templating, mostly pointing out how it reduces the dependency of having layout code directly in your application's logic. It makes things easier to reuse and makes for better code structure in the long run. They mention other templating engines like Smarty, PHPTAL and Twig, but focus in on the last for their code samples. They show basic templating, making reusable templates, applying filters and working with simple control structures.

tagged: templating tutorial introduction twig smarty phptal

Link:

PHPBuilder.com:
Smarty PHP Template Engine: Building PHP Apps in a Flash
Aug 10, 2011 @ 15:29:12

On PHPBuilder.com today there's a new tutorial from Octavia Anghel introducing you to Smarty, a PHP-based templating engine that can make creating the layouts and output of your site simpler and easier to reuse.

Smarty is a template engine for PHP whose main goal is to facilitate a very useful way to separate the business logic from the presentation logic. This article introduces Smarty and demonstrates how to install the template, create an application from scratch and interact with a database.

Installation of the tool is simple and using it is as easy as including the Smarty class, configuring it a bit through method calls and outputting to a template (tpl) file. A both a "Hellow World" and slightly more complex example using database results to build a table are included.

tagged: smarty tutorial introduction hellowworld database table template

Link:

PHPBuilder.com:
5 Popular PHP Template Engines Worth Checking Out
Apr 08, 2011 @ 18:23:40

On PHPBuilder.com today there's a new article looking at five PHP templating engines that they think are worth a look for use in your next project (or maybe in a current one).

In this article I'll introduce five of PHP's most popular templating engines, providing you with a basis for continuing your own investigations. Keep in mind however that this list is by no means definitive; if you have experience using a templating engine not discussed here, please tell us about it in the comments!

The five template engines the author chose to spotlight are:

  • Smarty
  • Dwoo
  • Twig
  • Savant3
  • PHPTal

Each comes with a description of its major features and a code snippet or two showing it in use.

tagged: template engine twig dwoo savant3 smarty phptal

Link:

Gonzalo Ayuso's Blog:
PHP Template Engine Comparison
Jan 17, 2011 @ 14:16:37

In a new post to his blog Gonzalo Ayuso has put together a comparison of a few PHP templating alternatives out there developers can use to further separate the view logic from the main parts of their application.

Template engines has a lot of features but I normally only use a few of them and the other features very seldom. In this performance test I will check the same features under different template engines to see the syntax differences and the performance. The template engines selected for the test are Smarty, Twig and Haanga.

He does some testing with each, creating a basic template to loop and create a basic table (template code and PHP code included) as well as an example using template inheritance with each. The reports of his tests are shared at the end with stats for memory used and execution time for both the normal templates and the inherited versions - but you'll have to check out the post for those results.

tagged: template engine compare benchmark twig haanga smarty

Link:

Shameer's Blog:
An Introduction to Smarty 3
Oct 07, 2010 @ 16:15:49

On his blog today Shameer has posted an introduction to Smarty 3, the upcoming version of the popular PHP-based templating engine. He talks about some of the improvements that have been made since version 2 in several categories including:

  • plugins
  • file structure
  • variable scope/storage
  • template inheritance
The Smarty 3 API (as of beta 8 ) has been refactored to a syntax geared for consistency and modularity. The Smarty 2 API syntax is still supported, butwill throw a deprecation notice. You can disable the notices, but it is highly recommended to adjust your syntax to Smarty 3, as the Smarty 2 syntax must run through an extra rerouting wrapper.

Code snippets are included for things like the new templating syntax, object handling, assigning variables and working with the inheritance now available.

tagged: smarty version introduction tutorial feature

Link:

NETTUTS.com:
Introduction to the Smarty Templating Framework
Sep 15, 2010 @ 15:08:35

On NETTUTS.com today there's a new tutorial introducing you to one of the more well-established templating tools for PHP-based applications - Smarty. It provides abstraction between your data and the output of the site, making is simpler to maintain in the long run.

Smarty is a PHP-based templating engine/framework. It allows you to further separate your business logic from its visualization, by removing as much PHP code as possible away from your views. Some developers and frameworks prefer not to use a templating engine, others do prefer them to using plain PHP in your views. Both points of view can be argued, and in the end, it’s mostly a matter of taste. Anyway, it's never a bad idea to try it out before deciding not to use it, and that's what this tutorial is about: trying out the Smarty Templating Framework.

They introduce it in a series of five steps (well, six):

  • What To Expect
  • Setting Up The Project
  • Creating The SMTemplate Class
  • Assigning and Formatting Variables
  • Working With a Layout
  • Creating Your Own Modifiers

Each of these comes with code examples and full descriptions so that, by the end of the tutorial, you'll end up with a full "Hello World" template system. The modifiers let you augment the base Smarty functionality to handle custom types and make handling the data even simpler.

tagged: smarty template framework tutorial introduction

Link:

Ivo Jansch's Blog:
PHP as a template language
Feb 15, 2010 @ 14:12:04

Ivo Jansch has a recent post to his blog talking about one of the great debates in the world of PHP - is the language by itself a good templating language (versus using something like Smarty)?

I think I've said it before. The tool you use should depend on the job you're trying to do. So to say that Smarty is wrong just because it is, does not feel right. I agree that in many cases PHP can be used as a template language just fine, but there are situations where a Smarty template (or any other templating engine) is just that more pleasant.

He's comparing them on aesthetics alone, showing two snippets of code - one templated via PHP and the other in the format that Smarty uses to generate a simple chunk of XML. For more examples of the Smarty format, check out their documentation.

tagged: template language opinion smarty

Link:

PHPBuilder.com:
Build an MVC Framework with PHP
Dec 18, 2009 @ 13:50:52

On PHPBuilder.com today there's a new tutorial that walks you through the process of creating a simple MVC framework in PHP based on Smarty, PostgreSQL and the PEAR XML_Serializer package.

PHP now enables you to build robust, manageable, and beautiful enterprise web applications. The best way to do that is to divide the application into three components: model, view, and controller. In other words, you need to separate the presentation, the database, and the business logic from each other. The most common approach for achieving this design goal is to adhere to a strict Model-View-Controller (MVC) framework.

He uses the example of creating an application (a feed reader) to show how the parts of the MVC will fit together as a whole. You won't find any code examples in the article, just an explanation of how everything works together. You can, however, dowload the source and follow along.

tagged: mvc framework tutorial smarty postgresql pear

Link:

PHPEveryday.com:
Smarty Template Engine Tutorial
Nov 09, 2009 @ 13:56:31

On the PHPEveryday.com site there's a recent tutorial with an introduction to Smarty, a popular PHP-based templating engine.

When doing web application development, it is important to make the separation between display design (presentation) work and creating application. Simply, you can create content before without having to consider display (presentation layer). Or, you can design the look without the care of application code. This is role that Smarty Templates want to play.

They look at getting it installed, some of the basics you'll need to know and a few more complex features like arrays, objects and variable modifiers.

tagged: smarty template tutorial

Link:


Trending Topics: