Markup Ain't Easy
or
How I Learned to love An
Object-Oriented RenderAPI
Carl Wiedemann • Drupalcon Austin
June 4, 2014 1:00PM - 2:00PM
Room 15 - Commerce Guys, 4th floor
https://austin2014.drupal.org/node/2618
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
So theming is
hard
Theming is hard
because
the render system
is complicated
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Things are getting better!
But rendering hasn't
changed much.
The render system
is complicated
because of
implementation
The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
We can't do this
The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
We can't do this
because we have no true API.
The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
We can't do this
because we have no true API.
src is in template_preprocess_image()
...which happens after template_preprocess_node() so the node template has no access
...because we want to render things on the fly (which is good)
…but arrays aren't smart.
Instead we have
drupal_render()
“ArrayPI”
How drupal_render() “works.”
1. Create a big array of stuff.
How drupal_render() “works.”
1. Create a big array of stuff.
2. Eat it!
How drupal_render() “works.”
1. Create a big array of stuff.
2. Eat it!
3. Return a string that came from
somewhere.
How drupal_render() “works.”
One of the longest procedural
functions in core.
drupal_render(), _theme()
185 lines, 244 lines
How drupal_render() “works.”
It's called a lot.
For non-cached single node
up to 8 recurses, 200+ times total
(via xhprof)
The problem with ArrayPI:
“I am not convinced that this
proposed change will give us
performance increase that will
justify the complexity we'll have
to introduce.”
- jessebeach
https://drupal.org/node/2099131
“array() is dead.”
- 8.x
long live array()!
-drupal_render()
This slide intentionally left blank.
Let's talk conceptuallyLet's talk conceptually
aboutabout
rendering.rendering.
What do we need?What do we need?
What do we need?What do we need?
I. An abstracted, alterable,I. An abstracted, alterable,
consistent model ofconsistent model of
structured content.structured content.
What do we need?What do we need?
I. An abstracted, alterable,I. An abstracted, alterable,
consistent model ofconsistent model of
structured content.structured content.
II. A sensible, accessibleII. A sensible, accessible
API for this model.API for this model.
We have arrays!
OBJECTS
Render API principles:
OBJECTS
{{ demo }}
http://github.com/c4rl/renderapi
Render API principles
1. Render arrays move to a
Builder pattern
Object creation is delegated
to a series of steps then finally
invoked.
Render API principles
2. Preprocess/process moves to a
Decorator pattern
Behavior added to object
dynamically at runtime without
affecting other objects of the
same class.
Render API principles
3. Building and decoration isn't
invoked until the builder is cast to
a string.
__toString() magic method
The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
We can't do this
because we have no true API.
src is in template_preprocess_image()
...which happens after template_preprocess_node() so the node template has no access
...because we want to render things on the fly (which is good)
…but arrays aren't smart.
The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
We can't do this
because we have no true API.
src is in template_preprocess_image()
...which happens after template_preprocess_node() so the node template has no access
...because we want to render things on the fly (which is good)
…but arrays aren't smart.
FIXED
...potentially :)
fixed
This slide also intentionally left blank.
@todo
Questions, feedback, reengage
discussion.
Proof-of-concept in 8.x sandbox,
tests & benchmarking.
Please evaluate this session
https://austin2014.drupal.org/node/2618
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Photos
http:/ en.wikipedia.org/wiki/George_Washington_University
http://flickr.com/photos/vanessaberry/4128711965
This work is licensed under a Creative
Commons Attribution-NonCommercial-
ShareAlike 4.0 International License.

More Related Content

PDF
Graphql
PPTX
Dynamic content with Angular
PPTX
Talentica - JS Meetup - Angular Schematics
PDF
Getting started with Angular CLI
PPTX
Git Perchè Usarlo
PDF
Creating BananaJS with Angular 2, Angular CLI, and Material Design
PDF
Visual Recognition with Anki Cozmo and TensorFlow
PDF
Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...
Graphql
Dynamic content with Angular
Talentica - JS Meetup - Angular Schematics
Getting started with Angular CLI
Git Perchè Usarlo
Creating BananaJS with Angular 2, Angular CLI, and Material Design
Visual Recognition with Anki Cozmo and TensorFlow
Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...

What's hot (20)

PDF
The Power of RxJS in Nativescript + Angular
PDF
RxJS: A Beginner & Expert's Perspective - ng-conf 2017
PDF
The Tale of 2 CLIs - Ember-cli and Angular-cli
PDF
RxJS - The Basics & The Future
PDF
A Practical Approach to React Native at All Things Open Conference
PDF
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
PDF
Create Alexa Skills using IBM Watson Conversation and Apache OpenWhisk
PDF
AngularJS RTP Slides - Angular 2 Demo #ngtattoo with Angular CLI, Newest New ...
PDF
A Tale of 3 CLIs - Angular 2, Ember, and React
PPTX
Documentation-driven development for Python web APIs v2
PDF
Your own on-demand Angular projects with ngX-Rocket
PPTX
API Conference 2021
PDF
Dsug 05 02-15 - ScalDI - lightweight DI in Scala
PPTX
Delivering successful API integrations with documentation-driven development
PDF
Jakarta Tech Talk: How to develop your first cloud-native Application with Java
PPTX
Documentation-driven development for Python web APIs
PDF
Principles of Iteration
PDF
Building GitLab
PPTX
PyBCN 2020
PDF
Eclipse Day India 2015 - Oomph
The Power of RxJS in Nativescript + Angular
RxJS: A Beginner & Expert's Perspective - ng-conf 2017
The Tale of 2 CLIs - Ember-cli and Angular-cli
RxJS - The Basics & The Future
A Practical Approach to React Native at All Things Open Conference
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
Create Alexa Skills using IBM Watson Conversation and Apache OpenWhisk
AngularJS RTP Slides - Angular 2 Demo #ngtattoo with Angular CLI, Newest New ...
A Tale of 3 CLIs - Angular 2, Ember, and React
Documentation-driven development for Python web APIs v2
Your own on-demand Angular projects with ngX-Rocket
API Conference 2021
Dsug 05 02-15 - ScalDI - lightweight DI in Scala
Delivering successful API integrations with documentation-driven development
Jakarta Tech Talk: How to develop your first cloud-native Application with Java
Documentation-driven development for Python web APIs
Principles of Iteration
Building GitLab
PyBCN 2020
Eclipse Day India 2015 - Oomph

Viewers also liked (8)

PDF
Introduction to Theme Preprocess Functions
PPTX
Leanmetings
PDF
Basic Drupal Recipes - BADCamp 2009
PDF
Slide for "Ingress night" 2014.8.22
PDF
Theme preprocess functions: An Introduction (DrupalCamp NYC 10 2011)
PDF
Theme Preprocess Functions: An Introduction (DrupalCon Denver 2012)
PDF
Rewriting the Drupal Theme layer
PPTX
Welcome to a Demonstration of LeanMail
Introduction to Theme Preprocess Functions
Leanmetings
Basic Drupal Recipes - BADCamp 2009
Slide for "Ingress night" 2014.8.22
Theme preprocess functions: An Introduction (DrupalCamp NYC 10 2011)
Theme Preprocess Functions: An Introduction (DrupalCon Denver 2012)
Rewriting the Drupal Theme layer
Welcome to a Demonstration of LeanMail

Similar to Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI (20)

PPTX
Draper - Visnupriya - spriteXchange
PDF
MuleSoft Manchester Meetup #3 slides 31st March 2020
PDF
I Love APIs - Oct 2015
PDF
Commonly used design patterns
PDF
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
PPTX
Angular Ivy- An Overview
PDF
Building APIs using Laravel - A simple approach to scale
PDF
Os Minnee
PDF
Top 8 Ruby on Rails Gems
PPTX
Onion Architecture with S#arp
PDF
Building a dynamic SPA website with Angular
PDF
Lightening a component based Rails architecture
PPTX
Deploying R for Production - SRUG
PDF
Container Driven Continuous Delivery
PDF
Machine Learning in the air
PPTX
AEM and Sling
PPTX
AEM and Sling
PDF
Jenkins vs. AWS CodePipeline
PDF
Angular 2 overview in 60 minutes
PPTX
Security Testing with Zap
Draper - Visnupriya - spriteXchange
MuleSoft Manchester Meetup #3 slides 31st March 2020
I Love APIs - Oct 2015
Commonly used design patterns
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
Angular Ivy- An Overview
Building APIs using Laravel - A simple approach to scale
Os Minnee
Top 8 Ruby on Rails Gems
Onion Architecture with S#arp
Building a dynamic SPA website with Angular
Lightening a component based Rails architecture
Deploying R for Production - SRUG
Container Driven Continuous Delivery
Machine Learning in the air
AEM and Sling
AEM and Sling
Jenkins vs. AWS CodePipeline
Angular 2 overview in 60 minutes
Security Testing with Zap

Recently uploaded (20)

PDF
Top AI Tools for Project Managers: My 2025 AI Stack
PDF
How to Set Realistic Project Milestones and Deadlines
PPTX
Post-Migration Optimization Playbook: Getting the Most Out of Your New Adobe ...
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
PPTX
AI Tools Revolutionizing Software Development Workflows
PPTX
ESDS_SAP Application Cloud Offerings.pptx
PDF
Mobile App for Guard Tour and Reporting.pdf
PDF
Enscape 3D Crack + With 2025 Activation Key free
PPTX
Independent Consultants’ Biggest Challenges in ERP Projects – and How Apagen ...
PDF
IDM Crack Activation Key 2025 Free Download
PDF
OpenTimelineIO Virtual Town Hall - August 2025
PDF
OpenAssetIO Virtual Town Hall - August 2025.pdf
PDF
Difference Between Website and Web Application.pdf
PDF
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
PPTX
Greedy best-first search algorithm always selects the path which appears best...
PPTX
Presentation - Summer Internship at Samatrix.io_template_2.pptx
PDF
WhatsApp Chatbots The Key to Scalable Customer Support.pdf
PDF
IObit Driver Booster Pro Crack Latest Version Download
PDF
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
PDF
SBOM Document Quality Guide - OpenChain SBOM Study Group
Top AI Tools for Project Managers: My 2025 AI Stack
How to Set Realistic Project Milestones and Deadlines
Post-Migration Optimization Playbook: Getting the Most Out of Your New Adobe ...
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
AI Tools Revolutionizing Software Development Workflows
ESDS_SAP Application Cloud Offerings.pptx
Mobile App for Guard Tour and Reporting.pdf
Enscape 3D Crack + With 2025 Activation Key free
Independent Consultants’ Biggest Challenges in ERP Projects – and How Apagen ...
IDM Crack Activation Key 2025 Free Download
OpenTimelineIO Virtual Town Hall - August 2025
OpenAssetIO Virtual Town Hall - August 2025.pdf
Difference Between Website and Web Application.pdf
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
Greedy best-first search algorithm always selects the path which appears best...
Presentation - Summer Internship at Samatrix.io_template_2.pptx
WhatsApp Chatbots The Key to Scalable Customer Support.pdf
IObit Driver Booster Pro Crack Latest Version Download
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
SBOM Document Quality Guide - OpenChain SBOM Study Group

Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI