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

Rob Allen:
Using ZF2 Forms with Twig
September 23, 2014 @ 09:28:53

Rob Allen has a new post today showing how to integrate Zend Framework 2 forms into a Slim framework based application. He started the topic in a previous post and continues, this time using the Twig templating framework to handle the rendering.

The ZF2 view helpers, formRow and formElement now look like Twig functions, however we don't want to have to rewrite all our ZF2 view helpers into Twig. Fortunately, Twig supports the concept of a undefined function callback is called whenever Twig encounters a function that it doesn't know how to call. We can use this to proxy through to the ZendView system and get it to render the ZF2 view helpers.

He shows how to use this callback functionality and a custom view layer with the Slim-Views component to render the output. He includes a simple Slim example, setting up the custom View class as a parser extension and how to register the callback to invoke Twig.

0 comments voice your opinion now!
zendframework twig render slimframework integration tutorial view

Link: http://akrabat.com/zend-framework-2/using-zf2-forms-with-twig/

NetTuts.com:
Working With Templates in Symfony 2
May 20, 2014 @ 10:34:05

NetTuts.com continues their introductory screencast series today with the latest episode focusing on using templates in Symfony 2. Other parts of the series have looked at using controllers, routing and some of the basics of the framework.

Today, let's learn about Symfony 2's Twig Templates. With Twig, you can seamlessly and painlessly integrate your PHP and HTML together, giving you a very clean looking presentation of your view code, without all the clutter of PHP tags, an overabundance of parenthesis, or semicolons. Instead, we have a simple and elegant syntax that we can use.

The screencast works with a sample application and a bundle to render the Twig template and includes examples of defining blocks of content and extending other templates. They also show you how to use layouts and pass data out to the template to be rendered on load. You can watch the screencast in-page or over on YouTube.

0 comments voice your opinion now!
introduction symfony2 template twig screencast series

Link: http://code.tutsplus.com/tutorials/working-with-templates-in-symfony-2--cms-21172

Custom Scripts Blog:
Dynamic layouts in Twig
December 18, 2013 @ 12:18:14

On the Custom Scripts blog they've shared a new tutorial showing you how to use the popular PHP templating tool Twig to create dyanmic layouts for your application.

Recently I worked on a project that needed dynamic layouts for each bundle. The idea was to have a base template, then several layout templates that each extends from the base. Each view would then extend from one of the layout files.

In the scenario I had, I needed to allow each bundle to specify there own stylesheets and javascripts. So each bundle needed to create a custom layout that overrides the parent stylesheet and javascript block adding their own content, and I did not want to re-create the layout files for each bundle.

He's created a base template for the entire site leaving areas for stylesheet and javascript injection as well as making it flexible enough to accept multiple column layouts. Layered on top of this is a base template for each bundle that's then extended via a custom extension class as needed. The PHP is also included to define this and the other extension classes you'll need to make the setup work.

0 comments voice your opinion now!
twig template dyanmic tutorial

Link: http://blog.customscripts.co.za/dynamic-layouts-twig/

Gonzalo Ayuso:
Sending automated emails with PHP, Swiftmailer and Twig
September 24, 2013 @ 11:40:57

Gonzalo Ayuso has posted a new tutorial today showing you how to combine PHP, Swiftmailer and Twig to send automated emails from your application.

My work as host is basically pick the place and encourage people to join to the Coding Dojo. One way of doing this (besides twitter buzz) is take my address book and send one bulk email to all of them inviting to join us. I don't like this kind of mails. They look like spam, so I prefer to send a personalized email. This email has a common part (the place location, the hour, the event description, ...) and the personalized part. I can do it manually, the list isn't so huge, but definitely that's not cool. Because of that I have done a little script to perform this operation.

His example extracts the information from a simple spreadsheet exported as a CSV file. He creates a simple Mailer class that uses Swiftmailer to do the actual sending. You pass in the Twig rendering object (Twig_Environment) that's used to render the email output. He includes a "Spammer" class that uses the Symfony EventDispatcher to send the email if everything works or an error email if something fails. He then drops it all into a Symfony Console command structure, defines several configuration settings in a "config.yml" and makes the script to execute the commands.

0 comments voice your opinion now!
email swiftmailer twig template tutorial symfony console eventdispatcher

Link: http://gonzalo123.com/2013/09/23/sending-automated-emails-with-php-swiftmailer-and-twig

Alessandro Nadalin:
Integrating Twig in Your Legacy PHP Code
June 18, 2013 @ 10:19:49

Alessandro Nadalin has posted a two part series to his site to help you get the Twig templating tool integrated with your legacy codebase.

It might happen that you are working on a legacy code that is years old, with its own templating mechanism1 that doesn't really allow you to take advantage of the benefits that a structured and object-oriented engine like Twig. In this situations, when a complete replacement would cost too much to your organization, you can take advantage of a wild integration between this advanced template engine and your existing code.

In the first part of the series, he proposes integrating it at the base level, essentially wrapping the "render" method of your framework of choice. In the second part of the series, though, he comes back with a "less wild" approach that also lets you take advantage of some of the other features twig has to offer. He modifies the previous example to output a template file and reuse that in the Twig "render" call.

0 comments voice your opinion now!
twig legacy codebase integration template render

Link: http://odino.org/integrating-twig-in-your-legacy-php-code

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


Dev.Umpirsky.com:
Use Poedit to Extract Translations from Twig Templates
September 04, 2012 @ 11:34:51

In this new post to the Umpirsky.com development blog, they show you how to use poedit to extract translations from Twig templates.

By default, Poedit does not have the ability to parse Twig templates. In Twig documenation there is a simple example which shows how to extract translations. This can work with few modifications, but I wanted to make reusable tool which will allow you to parse Twig templates just like you do with plain PHP templates.

The result is the Twig-Gettext-Extractor that's set up inside Poedit as a parser command for "*.twig" files. This automatically extracts the information so that the editor can read the data from the template.

0 comments voice your opinion now!
twig template poedit translation gettext extract


Dean Clatworthy:
Theming/styling error messages in Symfony 2
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.

0 comments voice your opinion now!
symfony2 error message theme style twig template tutorial


Reddit.com:
Symfony2... to Twig or not to Twig...
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.

0 comments voice your opinion now!
twig template opinion symfony2


Project:
Gitlist - A Git Repository Viewer (based on Silex & Twig)
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.

0 comments voice your opinion now!
silex microframework twig template gitlist repository viewer



Community Events





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


update symfony introduction api laravel install opinion tips package library zendserver language series podcast unittest framework interview community release deployment

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