Forest header image

Symfony Finland
Random things on PHP, Symfony and web development

Angular 2 server side rendering coming to Symfony and Twig

JavaScript has come to rule the web as of late. It's everywhere, powering things from the backend to the front end. One of the interesting things that have arrived is rendering the same exact code on the server and in the browser - this is known as Isomorphic JavaScript or Universal JavaScript.

Angular is a household name when it comes to JavaScript frameworks. They've been going through a major transition since the announcement of Angular 2. In the latest development Angular 2 will be getting PHP / Twig support for isomorphic rendering.

The news come from a talk on Angular 2 and the future of HTML5 apps from Brad Green. In this discussion he says the team is working on Universal Rendering - pre-rendering Angular 2 application state on the server - for platforms other than their native JavaScript. Among Java and .NET platforms, PHP and the Twig templating engine also gets a mention:

So the Angular and the Drupal development teams have started working together to bring Universal Rendering to PHP and Twig. The details remain murky on how exactly this will be implemented (using a Node.js server or a PHP library), but a PHP library (not an extension written in C) would be the easiest option for developers.

This feature is being developed by two product teams (Angular and Drupal) and there is an opportunity that the implementation will be coupled with Drupal:

In the past Drupal has been criticized for being a freeloader in the PHP community as of late, but this is a great opportunity for them to create something that is usable for hundreds of thousands of non-Drupal developers. We urge the Angular and Drupal teams to work to make this a generic PHP/Twig component and not something that is tightly coupled (ha-ha) with Drupal.
- Drupal team working on Angular 2 Universal support for Twig / PHP

While it will probably be relatively easy to plunder the code from Drupal. But ideally we would get a general purpose Universal Rendering component that could be installed with Composer and easily used across all kinds of different PHP applications. Not just Symfony and Drupal.

Learn more about Isomorphic Rendering:


Written by Jani Tarvainen on Tuesday March 29, 2016
Permalink - Tags: javascript, php, twig, symfony, angular

« Integrating eZ Platform + Doctrine Entities with the Symfony Framework - Local Symfony events in Paris, Oslo, London and Cologne this April »