Menu

React, etc. Tech Stack

React, Flux, GraphQL, Hack, HHVM...? All of this and more!

Render React.js Components in Drupal 8 with a Twig filter

React is becoming the gold standard for creating User Interface components in JavaScript. Many server applications are also written in JavaScript, which makes rendering React Components on the server a non issue.

PHP remains a popular language on the web and these two technologies (React and PHP) need to play nice together. React rendering using Node.js on the server side in PHP is completely feasible. Twig is a templating language for PHP that is widespread in Content Management Systems using Symfony and other tools.

If you want to render tags in Twig it's best to do this with a filter. Instead of creating Drupal 8 specific extensions, you can easily start with a base that can be shared across different tools using PHP. Rendering React components with Twig in Drupal 8 can be done by spawning a node process on the first uncached Twig call.

This is the easy way of going forward with Drupal 8 and React Component Rendering.

Written by Jorgé on Saturday November 14, 2015

Permalink - Tags: twig, react, drupal

« Facebook's design prototyping tool is Origami - WordPress, HHVM and PHP 7: Technical Debt Always Matters »