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

Laravel News:
Laravel Blade Components and Slots are coming to 5.4
Nov 16, 2016 @ 10:46:54

On the Laravel News site there's a post about an upcoming feature in the Laravel framework's Blade templating functionality: components and slots.

A new feature coming to Laravel 5.4 is the ability for you to add Components and Slots to Blade templates. This feature was inspired by Vue.js and allows you to simplify building HTML elements into reusable areas.

In most applications you have a master layout and then sub views that extend it. [...] Using the new Laravel Blade Components you can create [a template] with a special variable [for easy replacement].

The post then shows how to "reimagine" views using this slots and components functionality in a simple template/view example, replacing data based on names rather than it having to be passed to the view as data.

tagged: laravel blade template component slot data replacement framework

Link: https://laravel-news.com/2016/11/blade-components-slots/

Matt Stauffer:
Customizing pagination templates in Laravel 5.3
Jul 27, 2016 @ 12:33:36

Matt Stauffer is back with another in his series of posts about the new features coming in the v5.3 release of the popular Laravel framework. In the latest post he looks at pagination improvements allowing you to customize the related templates.

Laravel's pagination library is brilliant, because pagination is a common task that is a surprising amount of work to implement. In the past, if you wanted to customize your pagination templates, it was just as simple to customize your pagination template as it was to work with the rest of the pagination library.

However, for the sake of making the pagination library easier to extract for non-Laravel projects, Laravel 5.0 (or maybe even earlier?) introduced a much more complex—but more portable—system for pagination templates. Thankfully, in Laravel 5.3, we're going to go back to how it always was: simple and easy.

He then gets into the basics of how pagination works in Laravel applications (not the template part, the backend) using the Task::paginate handling. He includes the view to just show the results and the current view handling for the pagination links. Finally he shows how to customize the template in v5.3 by registering a custom view to the partials.paginator and using the links method to inject them into your current template.

tagged: laravel template pagination customize tutorial series v53 framework

Link: https://mattstauffer.co/blog/customizing-pagination-templates-in-laravel-5-3

Symfony Finland:
Universal Rendering in PHP/Twig could be done with the Angular 2 Template Compiler
May 09, 2016 @ 11:15:01

The Symfony Finland site has a post about Angular 2, its server-side rendering support and how Symfony can fit into the picture.

At the ng-conf event in May 2016 there were sessions discussing how Angular 2 can support server side rendering in various platforms. If you're working on a project running on Node.js, then Angular 2 is a native citizen. For other options like ASP, Java and PHP there are a few options on the table.

[...] Later during the ng-conf more details on the Server Side Rendering (Universal Rendering in Angular lingo) can be implemented in different environments to improve first page load experience. [...] The downside of these approaches is that you need to add additional complexity either by adding a dependency to an external service or require a rather exotic PHP extension at this point.

Instead he suggests using Twig along with the Angular 2 template compiler and some custom extensions to the base templating to format the output as Angular is expecting it. He talks about how the current backend rendering of templates could easily be translated to this handling. He also suggests that even just partial server-side rendering might be enough to help with the performance of the application.

tagged: symfony universalrendering angular2 twig template backend frontend performance

Link: https://www.symfony.fi/entry/universal-rendering-in-php-twig-with-angular-2-template-compiler

Matt Stauffer:
The auth scaffold in Laravel 5.2
Jan 11, 2016 @ 10:06:29

Matt Stauffer has continued his series about some of the new features in the latest release of the Laravel framework (v5.2) with this post looking at the new auth scaffolding it makes available.

If you're like me, many of the applications you build in Laravel have a similar Saas-type framework: user signup, user login, password reset, public sales page, logged-in dashboard, logout route, and a base Bootstrap style for when you're just getting started.

Laravel used to have a scaffold for this out of the box. It disappeared recently, to my great chagrin, but it's now back as an Artisan command: make:auth.

He talks about what all the scaffolding builds out including templates, routes and controllers. He provides examples of some of the generated code and what the output of these simple templates looks like (including a basic Bootstrap layout).

tagged: laravel framework auth scaffold tutorial example login user template controller route

Link: https://mattstauffer.co/blog/the-auth-scaffold-in-laravel-5-2

SitePoint PHP Blog:
Transphporm – a Different Kind of Template Engine
Dec 17, 2015 @ 09:42:54

The SitePoint PHP blog has posted a tutorial on a "different kind of template engine" that makes use of selectors and placeholders to define templates and replace data: Transphporm. In this article they introduce you to the library and give some examples of it in action.

Many PHP template engines (Smarty, Blade, Twig…) are little more than abstracted PHP code, making it easier to write loops, if/then/else blocks, and display variables with less verbosity than vanilla PHP. These traditional template engines require the designer to have an understanding of special syntax. The template engine must also be in place and operational in order to parse data and thus completely render the final design. Nothing wrong with this.

Transphporm follows a different approach that is generally known as “template animation”. What this means is that the web designer creates the entire HTML/CSS/JS page including placeholder content such as “Lorem Ipsum”, then the template engine comes along and replaces parts of the DOM with new data before the final render.

The benefit of this kind of templating is that the designer or one creating the templates doesn't need to know anything about the templating software or a special syntax. Transphporm uses CSS-style selectors to define the replacement location and the data that should fill that spot. They give an example of a simple HTML page with plenty of markup defining the locations of the placeholders. They then show how to define a "tss" configuration, listing out all of the selectors and the content to push in as a replacement. They also talk a bit about DOM concerns, what happens if the template changes and the selector is no longer valid and how to help this with partials. Finally they look at some of the more advanced features like using arrays, working with attributes and conditional changes (among others).

tagged: transphporm template language css selector tutorial

Link: http://www.sitepoint.com/transphporm-a-different-kind-of-template-engine/

Programming With Yii2: Using the Advanced Application Template
Nov 24, 2015 @ 10:10:47

NetTuts.com has continued their series around programming with the Yii2 framework in this latest tutorial looking at the use of the Advanced Application Template, an enhanced boilerplate system that provides a bit more built-in functionality than the default application setup.

In this Programming With Yii2 series, I'm guiding readers in use of the Yii2 Framework for PHP. As you begin to use Yii for real development, you may want to start your next project with its Advanced Application Template. Among other things, it provides integrated user management features as well as two applications, one for the consumer-facing front end and the other, an administrative back end.

In this tutorial, I'll introduce you to the Yii2 Advanced Template and guide you through the basic setup and usage.

They start with a look at how the Advanced Template is different from the default one (a checklist) and how to set up a new project using it. They show how to configure the database connection and execute the required migration to build out the user table. They also walk you through the Apache setup for local development and what the resulting "Congratulations" page should look like. The remainder of the post explores the user management section, showing how to configure email delivery, signup, login and password reset requests.

tagged: yii2 framework series advanced application template user management tutorial

Link: http://code.tutsplus.com/tutorials/programming-with-yii2-using-the-advanced-application-template--cms-24994

Sylius Blog:
Sending configurable e-mails in Symfony
Oct 05, 2015 @ 11:15:46

In a post to the Sylius blog Mateusz Zalewski shows you how to create configurable emails in your Symfony-based application with help from a custom bundle they've released to help make it a much simpler process.

Every developer, during their adventure with PHP programming has been struggling with sending emails in a web application. However using PHP send() function is often insufficient for common web applications, when you need templates, variables, configurations etc.Fortunately, Sylius provides SyliusMailerBundle and Mailer component, with some awesome features. [...] Of course, this bundle and component are fully decoupled and can be used in any Symfony application.

They walk you through the installation (via Composer) and configuration of the bundle, adding it's dependencies to the kernel of your application. He shows how to configure the container with connection information (like the name and from values) and update your database with the tool's migrations. From there he shows how to customize your emails, making use of the Twig template handling to define the body contents. The bundle also makes it possible to define custom email types with different settings for each. Finally they show how to send the emails, grabbing the sender information and sending the email, either more manually or via a custom defined email type.

tagged: symfony email configurable tutorial bundle customize template sender

Link: http://sylius.org/blog/sending-configurable-e-mails-in-symfony

Barry vd. Heuvel:
Comparing Blade and Twig templates in Laravel
Aug 26, 2015 @ 10:02:32

Anyone that has looked at using a templating library in their application has probably come across both Blade (in Laravel) and the Twig libraries. In a post to his site Barry vd. Heuvel compares these two templating libraries based on their features, security and (briefly) performance.

In my company, we use Twig instead of Blade for our Laravel projects. I know there are a lot of developers that also prefer Twig over Blade. So the question ‘Why choose Twig over Blade?’ often pops up. The reason is usually just a matter of preference, but in this post we’re going to compare the Blade and Twig templating engines side-by-side.

He starts with an "about" for each library, giving some basic background and examples of simple templates. He talks about using Twig in Laravel (vs Blade) and then lists some similarities and differences between the two. Following this high-level list he gets into more detail on each feature of the libraries including:

  • Outputting variables
  • Control structures
  • Template inheritance and sections
  • Security and context

Each section includes a description of the feature and a template example showing how it's put to use. He ends the post with his thoughts on which one you should pick for your project, but notes that, like many things in development, the answer is "it depends" on your project and team's needs.

tagged: compare blade template twig library feature overview example

Link: http://barryvdh.nl/laravel/twig/2015/08/22/comparing-blade-and-twig-templates-in-laravel/

Knp University:
Our favorite PhpStorm Live Templates: Share yours
Aug 21, 2015 @ 10:49:39

The Knp University site has a posted an article where they've shared their favorite PHPStorm Live templates, a set of handy shortcuts that can make for less typing on your part and, as a result, less development time spent on common keystrokes.

Most editors have a feature like this, and if you’re not leveraging them, you’re slowing yourself down. Seriously: taking a few minutes to get into these now could add up to a lot of hours saved in the future. The vim users at KnpLabs love this kind of stuff, and have published their own snippets (docteurklein, PedroTroller, Einenlum).

In our tutorial about live templates, we turn formhandle into a snippet that types about 10 lines of form-handling boilerplate code from 10 characters of text. So I started wondering: what are some other awesome live templates we should all be using?

To this end, they've created a repository to store some of these helpful shortcuts. Their list so far includes shortcuts for a 404 if statement, several Twig tags, several for use in a controller context and YAML formatting. The repository includes instructions on how to install the shortcuts and how to include only the ones you want.

tagged: phpstorm live template share repository starter snippet shortcut

Link: http://knpuniversity.com/blog/phpstorm-live-templates

SitePoint PHP Blog:
Drupal 8 Theming Revamped – Updates and New Features
Aug 11, 2015 @ 11:08:28

The SitePoint PHP blog has a tutorial posted introducing some of the updates to the theme functionality in Drupal 8 including some new features.

If you are a Drupal developer who has dabbled in theming older versions of Drupal (5, 6, 7) you understand why frustration is the trusty companion of any Drupal themer. Luckily, though, Drupal 8 promises so many improvements that even the Angry Themer is happy for a change. It is only natural we jump in and start looking at what these improvement are.

They talk about the changes in:

  • creating a module and defining its theme
  • that Twig is now the template library
  • updates to template handling
  • how to debug themes/templates
  • working with assets and libraries

Each topic includes a summary of the changes or more information about the topic including links to other resources with more information about each.

tagged: drupal8 update theme feature twig template debug asset library

Link: http://www.sitepoint.com/drupal-8-theming-revamped-updates-and-new-features/