On the TechFounder blog, Eran Galperin has taken a look at object-oriented templating in PHP applications, comparing the older search and replace method with the inclusion of PHP-based templates.
PHP as a language can be considered a templating system, as in its root it was meant to modify HTML pages dynamically. The need for more structured templating systems arose as PHP applications have grown more and more complex, giving birth to much more specialized and focused solutions.
He illustrates with an object replacement example - parsing the template as a PHP script and replacing any objects found with the corresponding object property value.
Taylor Luk submitted some info about a project he's been working on for a while and is ready to release into the wild and see how useful it can be for others - H2o Template, a Django-inspired templating system.
I have been developing this for quite a while, started as a fun project to do django like syntax and compiles down to php code. Unlike the last django-like template for Zend Framework, this one is more stand alone. After couple major rewrite, now i am releasing 0.3 beta.
The syntax of the templates is pretty similar to Django and it includes a built-in caching driver, an extension system that allows for external filters/tags/extensions to be added in easily and internationalization support. He's currently using it on a CakePHP website in a view class on a production system.
New on the AskAboutPHP.com blog, this tutorial concerning CodeIgniter view organization has been posted:
Trying my hands at using CodeIgniter, one of the first obstacles I had was how to organize my 'blocks' on a page. Without knowing any better, I thought I had to reiterate the same view calls in every function within the controller, making the controller codes very messy. It turns out that CodeIgniter allows us to nest views within views, and that has made things a lot simpler for me.
Instead of loading and calling the view() method over and other in his actions, he chooses to make a "template" view with each of the other calls to view() contained inside. Then you just pass in the data you want the view to render and call that template view. This also allows you to easily create a site-wide template.
The NETTUTS site has a tutorial posted today that's part one of a series looking at the Gamepress theme for WordPress and how to customize it to your needs.
GamePress is a "Gaming News & Reviews" theme for WordPress and currently one of the most popular themes at ThemeForest. It is the most advanced theme I've created so far, and really pushes what the WordPress engine can do!
This first of two parts introduces you to the template and the various components/content blocks it contains like the Features Slider, Latest Headlines, Older News and the Reviews page. You can check out a live demo of it in action to see what you think.
In this new post to the SitePoint PHP Blog there's a look at using a small templating engine recently released by Fredrik Holmstrom that takes a different tack on working with template files - it parses them into a DOM structure.
The main difference to traditional template engines (Such as Smarty), is that the template it self doesn't have any imperatives within. In fact, the template doesn't even have to be written to the template engine, to be used - Any markup can be used as a source.
The templating system uses Domlings, bits of HTML to match against and replace with the bound information. A few examples are included - a simple binding, how to switch out a block of HTML, pushing it back in and looping over a block of information to do some search and replace.
In a new post today Alex Netkachov shows a handy little tip for the Eclipse users out there that want to use the @var type hint in their code.
@var variable type hint is very useful, but adding it a little bit complex: usually you need to type the class name or copy/paste it from somewhere. But with Eclipse PDT templates you can simplify this and add an autocomplete for variable name and class name.
It's a simple one-step process - you just add in a new template to your Eclipse application and it will prompt you to select the class name from a list and drop it right in. No more cut and paste needed!
NETTUTS.com has posted the second part of their tutorial on how to create a simple framework of your own in a PHP5 environment.
With the basic structure for our Framework in place, it is time to start adding functionality to it. In this tutorial we will create a template manager and database handler, bringing us a step closer to a powerful Framework fit for use for almost any project. If you haven't already, be sure to review Part 1 of this series first!
This time they look at a few different parts of the framework, namely the database handler, the template manager and loading data into the framework. The end it with an example of the simple framework in action - pulling a list of members from a database and displaying them to the page.
On the Total PHP blog today, there's a new tutorial showing how to make a very basic template editing form to update the templates for your site.
A common feature to CMS scripts is a browser based means of editing your templates. This can be helpful if you manage your site remotely or on the move quite often. In this tutorial we walk through how to create a simple template editor in PHP.
The process is pretty simple - a form that allows you to either create or edit a current template file and some PHP that handles the submit. It takes in the data from the textarea and pushed it out to the correctly named file. It's a pretty simple setup and it requires that the web server user can write to the files, but it can be a big help when you can't get into the machine otherwise.
The ProDevTips blog continues their series on using Doctrine in a sample application in this new part, a look at paginating the results from your database query.
Things are starting to become more and more feature complete. Let's look at how to implement general search and pagination.
They define the search to perform ($searchConf) and the pagination parameters ($pageConf) and apply them to their current Doctrine setup applying a simple layout to make the numbered links for switching between pages. They also define the search() method that pulls the results from the table to push into the pagination component.
Recently Chad Kieffer made a post to his blog about a handy little feature of the Eclipse IDE that can help you speed up your development - snippets and templatings.
You already know that Eclipse PDT provides autocompletion and hints for PHP's built in functions. In addition, commenting your code with PHPDoc adds autocompletion and hinting for your application's classes, methods, and variables. If you haven't already discovered, Eclipse PDT also provides autocompletion of PHP's control structures, class definitions, and methods through code templates.
He gives examples of both the templating and the snippets - inserting a switch() statement template and how to create a custom snippet of whatever code you choose.