 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Extending Twig Templates: Inheritance, Filters, and Functions
by Chris Cornutt April 16, 2013 @ 11:05:22
On PHPMaster.com today there's a new tutorial for the Twig templating users out there showing you how to extend your templates via inheritance, filters and functions - all abilities already built in to the tool.
When working within an MVC architecture, it's common to use a template library to populate the dynamic content of our views. There are dozens of such libraries available for PHP, but Twig is one of the standouts because of the ability to extend core features with custom implementations. In this article we'll explore how Twig templates can be extended using template inheritance, filters, and functions.
He starts first with some of the common limitations of templating frameworks (extension) and how Twig gets around this. He shows the use of the "extends" keyword and the "block"/"endblock" for splitting up the page into reusable chunks. He also shows how to use filters and functions in your Twig tags, allowing for more customized content and functionality for your output.
voice your opinion now!
taig template tag filter function inheritance tutorial
PHPMaster.com: Overriding Strategy Logic - The Template Method Pattern
by Chris Cornutt September 25, 2012 @ 08:58:01
On PHPMaster.com there's a new tutorial posted talking about the Template Method Pattern to help make some sense (and make easier to use) your implementation of the Strategy pattern.
This bring us back to the question whether it's feasible to eliminate duplicated strategy logic via Inheritance rather than switching over to plain Composition. Indeed it is, and the clean up process can be conducted through an ubiquitous pattern known as Template Method. [...] Simply put, there's a base class (usually an abstract one), which declares a concrete method (a.k.a. the template) responsible for outlining the steps or hooks of a certain algorithm. Most of the time the base type provides boilerplate implementation for some of those steps and the remaining ones are delegated to subclasses.
The subtypes then override the base's functionality and extend it with their own. They show an example of this by making a jQuery image slider (using this plugin) , an "AbstractCycleSlider" class and two subclasses for two other types - "FadeSlider" and "ScrollSlider", each outputting their own HTML. It also shows how to implement a slider using a different plugin and output both in the same script.
voice your opinion now!
strategy logic designpattern template method abstract subtype
Dean Clatworthy: Theming/styling error messages in Symfony 2
by Chris Cornutt August 30, 2012 @ 11:40:40
For the Symfony2 users out there, Dean Clatworthy has a handy tip to help you customize the output of your application a bit more - a method for styling the error messages coming from forms using a custom template.
I spent a large portion of my day today trying to customize the HTML produced by Symfony 2 for form errors. The documentation has a section on how to do this, but for the life of me, I could not make it work. Here is a working, re-usable solution.
His solution involves the creation of a template in your "/Resources/views/Form/" directory that contains a Twig template for the error set output. This is then applied in your view using an additional parameter on the error output tag, including this new template from the "Form" directory. This sort of styling could also be applied if you needed custom elements with their own layouts in your forms as well.
voice your opinion now!
symfony2 error message theme style twig template tutorial
NetTuts.com: An Introduction to Views & Templating in CodeIgniter
by Chris Cornutt July 09, 2012 @ 12:09:48
NetTuts.com has a new tutorial that will interest the CodeIgniter developers out there about using views and templates in your CI applications.
Views are a key ingredient in any MVC application, and CodeIgniter applications aren't any different. Today, we're going to learn what a view is, and discover how they can be used to create a templating solution for your CodeIgniter projects. The first part of this tutorial will educate complete beginners to CodeIgniter on what a view is, and how to use them in a typical application. The second half will discuss the motivations for finding a templating solution, and guide the reader through the necessary steps for creating a simple, yet effective templating library.
They introduce you to some of the fundamentals behind views, templating, using multiple views and using the templating to push values out to the site.
voice your opinion now!
views template codeigniter tutorial
PHPMaster.com: 5 Inspiring (and Useful) PHP Snippets
by Chris Cornutt July 02, 2012 @ 10:58:45
On PHPMaster.com there's a new tutorial that shares some useful PHP snippets that you could use in your development.
"X PHP Snippets" type articles abound on the Internet, so why write another one? Well, let's face it… the PHP snippets in them are generally lame. Snippets that generating a random string or return $_SERVER["REMOTE_ADDR"] for the IP Address of a client really aren't that interesting and are of modest usefulness. Instead, here's five snippets that you'll no doubt find interesting and useful, presented along with the problems that inspired them. I hope the creativity in many of them inspire you to write better and more creative code in your own day-to-day endeavors.
Their "five tips" are about:
- Generating CSV files from an array of data
- Autoloading classes (in a PSR-0 way)
- Parsing data with the unpack function
- Templating in HTML (creating a "View" object)
- Using file_get_contents as a cURL Alternative
voice your opinion now!
snippets csv autoload unpack template filegetcontents
DZone.com: How to Build PHP 5.4 Applications with Visual Studio
by Chris Cornutt June 29, 2012 @ 08:26:08
On Dzone.com today there's a new post showing you how to build PHP applications with Visual Studio based on PHP project templates.
Developing web applications with PHP is cool, especially when you have the right development tools and even with more features added in PHP 5.4. But each time I left the comfort of Intellisense in Visual Studio to develop PHP applications using Zend or Netbeans for PHP, I was not always satisfied with those IDEs' code complete features. Thus, I decided to search for any available plugin that will provide this feature in Visual Studio.
The plugin used is on from Jcx.Software Corp. It adds in the PHP templates and Intellisense support for PHP code completion. He also shows how to set up an IIS server to work with it to make it easier to test your application.
voice your opinion now!
application development visualstudio template intellisense iis
Reddit.com: Symfony2... to Twig or not to Twig...
by Chris Cornutt May 30, 2012 @ 11:32:30
In this recent post on Reddit.com a developer of a Symfony2 application asks, "to Twig or not to Twig for templating in his views.
Hey there... long time Symfony 1.x enthusiast here, finally getting my feed wet with Symfony2. I pose this question to the Symfony2 developers out there: Who's using Twig for templating? Why or why not?
The answers tange from the obvious "yes" and "no" options out to suggestions that even using templating languages are a bad idea. A few point out that the "separation of concerns" as a valid reason while others discount them by dismissing the "designers don't have to learn a language" myth that seems to still be so popular. There's also a few mentions of other templating projects like Smarty and Savant.
voice your opinion now!
twig template opinion symfony2
Paul Reinheimer's Blog: Sending Mail
by Chris Cornutt May 23, 2012 @ 12:58:29
Paul Reinheimer has posted about his experiences with sending mail, specifically as it relates to using the Zend_Mail component from the Zend Framework to handle the details.
Like every product, Natural Load Testing needs to send some mail, having written and re-written a bunch of different blocks of mail code over the years, I wanted to come up with something that would work now, and continue to serve us well into the future.
He chose Zend_Mail to fulfill some of his requirements (multipart emails, sending custom emails, templates for automatic emails) and includes some sample code showing it at work. The result is an object that can be created and, by calling a "basic" method, can send an email based on an HTML template (using the HTML Email Boilerplate for the base styling).
voice your opinion now!
send email zendmail tutorial template
Project: Gitlist - A Git Repository Viewer (based on Silex & Twig)
by Chris Cornutt May 18, 2012 @ 09:45:46
Klaus Silveira has submitted a project he's been working on to make browsing through git repositories a bit simpler with a local tool - gitlist.
GitList is an elegant and modern web interface for interacting with multiple git repositories. It allows you to browse repositories using your favorite browser, viewing files under different revisions, commit history, diffs. It also generates RSS feeds for each repository, allowing you to stay up-to-date with the latest changes anytime, anywhere. GitList was written in PHP, on top of the Silex microframework and powered by the Twig template engine. This means that GitList is easy to install and easy to customize. Also, the GitList gorgeous interface was made possible due to Bootstrap.
Since it's just a PHP-based application, installing it is as easy as cloning the source to a web-accessible directory and setting up a "config.ini" file with your settings. You can find out more about this project based on the popular Silex microframework on its GitHub page.
voice your opinion now!
silex microframework twig template gitlist repository viewer
|
Community Events
Don't see your event here? Let us know!
|