News Feed
Sections




News Archive
feed this:

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

SitePoint PHP Blog:
Introduction to JadePHP
April 10, 2014 @ 10:30:30

Lukas White has posted an introduction to JadePHP to the SitePoint PHP blog today. JadePHP is a port of the popular Jade templating language more often used in Javascript.

There are dozens of templating engines out there, with options such as Smarty, Twig (used in the upcoming version of Drupal) and Blade (the default for Laravel) among the best known - as well as vanilla PHP, of course. [...] One which differs quite significantly from most is Jade, an engine usually associated with Javascript applications - it's supported out-of-the-box by Express for Node.js, for example. It's Jade I'm going to look at in this article; or more specifically the PHP port JadePHP.

He starts by briefly talking about HAML, a markup language that aims to make it easier and cleaner to write well-formatted HTML documents. Jade creates the entire document this way, meaning you could use it even without any templating needs (just outputting normal HTML pages). He shows you how to get started with the code and provides a simple example of a basic HTML page without any template objects to replace.He explains the markup and what each part does before moving on and showing how to add in the dynamic content and logic. He finishes off the tutorial by answering the question "Why use Jade?" touching on some of the good and bad of the templating engine.

0 comments voice your opinion now!
jadephp templating haml markup library tutorial

Link: http://www.sitepoint.com/introduction-jadephp

ServerGrove Blog:
Symfony2 components overview Templating
March 14, 2014 @ 10:11:46

The folks at ServerGrove have posted the latest in their series focusing in on various components of the Symfony2 framework. This time they look at the Templating component, useful for working with the output from the application, web or otherwise.

The Templating component provides an engine-agnostic infrastructure to load template files and render them using the input variables. Although the component provides methods for creating template systems, we are going to focus on how to integrate third-party template engines like Twig and Smarty, and how to use the right engine based on the templates file extension.

The post talks about typical PHP output (with escaping) and shows the difference between a call with htmlspecialchars and the use of the Template component to render a view. An example is also included showing the use of other template engines into the template object, plugged directly into the "render" method. The end of the post also briefly mentions an alternative template language, Plates, an option similar to Twig but uses native PHP rather than tags and placeholders.

0 comments voice your opinion now!
symfony2 component overview templating tutorial

Link: http://blog.servergrove.com/2014/03/11/symfony2-components-overview-templating/

Anthony Ferrara:
On Templating
December 11, 2012 @ 11:50:31

In this latest post to his site Anthony Ferrara take a look at templating in web applications - more specifically as it deals with his experience with the Mustache templating engine.

I've been playing around with tempting engines a lot lately. For a recent project, I needed the ability to re-use the same template set in both JS and PHP (coupled with the History API, providing seamless dynamic behavior, yet still having raw content pages). Realistically today, there's only one choice for that sort of requirement: Mustache. I've learned a lot while playing with Mustache, and it's really changed my entire viewpoint on presentation layer construction.

He briefly gives an overview of "the past" of templating in PHP (including a mention of Smarty) and how templating tools - like Mustache - have helped to improve the situation, especially when it comes to the separation of presentation and processing. As an alternative, there's also a mention of the Twig templating engine in the comments, another popular option from the Symfony project.

0 comments voice your opinion now!
templating presentation mustache twig introduction opinion


Sean Coates' Blog:
PHP as a templating language
May 15, 2012 @ 10: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).

0 comments voice your opinion now!
templating language smarty mustache handlebars javascript api


WorkingSoftware Blog:
Your templating engine sucks & everything you've written is spaghetti code
December 14, 2011 @ 12:03:54

In a bit of a ranting post on the WorkingSoftware.com.au blog Iain Dooley shares his opinion about most of the code he's seen, specifically related to templating engines: "Your templating engine sucks and everything you have ever written is spaghetti code (yes, you)".

Templating is a real hot button in the web development community. [...] The high horses that people usually get on are that all too familiar TLA MVC (Model/View/Controller) architecture and "separation of presentation and business logic". The poor pedestrians upon which they look down are those who have written "spaghetti code" - templates where presentation logic, markup, business logic, database access configuration and whatever else you might imagine are mixed up in the same file. Well, I've got some news for you: you're all wrong.

He points out that, with most of the major templating tools out there, there's most people still put some sort of business logic in their templates. Rarely will you find a "pure" template that only echoes out the data. He gives an example of a Mustache template with "empty" logic in it. He shares a new term his coined too: "Template Animation". This is the separation of the templating process as it is usually done and splitting it so that the output is a modified DOM resource rather than a static template.

He talks about some of the advantages of this approach and an example of its use in an example of a logged in user vs not logged in user as well as a brief discussion of Markdown/HAML.

The only thing that Template Animation advocates is that the technological barrier between the frontend and the backend is never crossed - that our templates are truly logic-less.

There's lots of comments on the post already - everything from support of the idea to systems that already implement this sort of idea to disagreeing opinions.

0 comments voice your opinion now!
opinion templating engine logic separation templateanimation


Smashing Magazine:
Getting Started With PHP Templating
October 18, 2011 @ 09: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.

0 comments voice your opinion now!
templating tutorial introduction twig smarty phptal


Ryan Mauger's Blog:
Using Twig with Zend Framework
May 05, 2011 @ 08:28:18

Ryan Mauger has written up a new post about an integration he's done using the Twig templating engine (from be Symfony community) with his Zend Framework application to make view handling simpler.

Mostly I thought [what Twig offered] were silly things that were not really needed unless you had a team of designers to work with, however, during my exploration, a couple of things occurred to me that I had not considered about templating systems before. One being the enforced separation of concerns they provide; you simply cannot do anything from inside them which you shouldn't be, keeping your presentation very very clean. The second, being that they're not all as terrible as Smarty.

He helps you get Twig installed (via PEAR chnnel) and includes the code for an application resource and the changes you'll need to make to your application.ini to get things working. He uses a base controller setup, so he shows how to introduce a "twig()" method into that to help with rendering. Finally, there's a sample class included that includes two actions, both using this "twig()" method to pas the output data through the twig interpreter and out to the view.

1 comment voice your opinion now!
twig templating tutorial zendframework example pear


Zend Developer Zone:
Creating Web Page Templates with PHP and Twig (part 1)
April 07, 2011 @ 12:44:43

On the Zend Developer Zone today there's a new tutorial from Vikram Vaswani about using the Twig templating engine in your application. It's part one of a series that introduces the library to you and includes examples of some of the most common templating logic.

Most PHP frameworks, including Zend Framework, Agavi, CakePHP and CodeIgniter, come with built-in templating to enable this separation. However, if you're not a big fan of frameworks, or if your project is small enough that you don't need the additional overhead, you can also consider using a standalone template engine to obtain the same benefits. A number of such engines exist - you've probably already heard of Smarty, Savant, Dwoo and others - and in this article, I'll introduce you to one I discovered rather recently, called Twig.

The Twig project gives you a framework-independent tool for creating simple (or complex, if you'd like) templates for the output of your site. He shows you how to get it installed (via PEAR) and provides some sample templates for things like:

  • using conditionals (if/else/etc)
  • looping
  • working with arrays from PHP
  • including other templates
  • using included filtering on data
0 comments voice your opinion now!
tutorial twig templating introduction


Community News:
Has Smarty's Time Come?
January 11, 2008 @ 12:53:00

As Paul Jones mentions, there's a sort of force in the PHP community that seems to be pushing back at the Smarty templating system and calling it unnecessary.

He points out Hasin Hayder's post on the subject. Hasin (ironically author of a Smarty book) has recently come to the conclusion that there "is no need to use an external template engine like smarty".

Some nice guys over there developed smarty and it saved life of a lot of developers (i mean developers). But that time is over. Seriously why the hell I need to learn a new templating language when a "echo" does the thing much better.

Judging by the responses to both Hasin's post and Paul's post it seems like quite a bit of the PHP community agrees (including Michael Kimsal, Harry Fuecks and Brian Lozier).

0 comments voice your opinion now!
smarty templating framework obsolete language smarty templating framework obsolete language


Rob Peck's Blog:
PHP Templating Celebrity Deathmatch!
August 14, 2007 @ 15:37:50

The Code Lemur blog (as penned by Rob Peck) has a new post - a "deathmatch" for two of the PHP-associated templating solutions out there in a fight to the finish - Smarty and Blitz.

In this test, I am going to be comparing Smarty (the most widely used PHP templating engine and an official PHP project), Blitz (a new templating engine currently under very active development that is native compiled as a PHP extension), and standard PHP includes.

He compares them on three different levels - instantiation, simple template rendering, and complex testing. Each time, there's a victor but in the end, there's really only one "winner" - the PHP language itself that does a great job of templating things easily without the overhead of adding in external libraries.

0 comments voice your opinion now!
templating deathmatch blitz smarty compare templating deathmatch blitz smarty compare



Community Events





Don't see your event here?
Let us know!


library bugfix voicesoftheelephpant tips community framework deployment series release introduction opinion api install symfony package podcast language interview list laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework