Render arrays vs Theme functions?

1 reply [Last post]
Last seen: 8 years 39 weeks ago
Joined: 2011-08-08


Firstly wanted to say thanks for a great video series, I've learnt more in the past few days since I've signed up than I had in around 4 months trying to find the time to read through books, and docs and example code - best video tutorials on Drupal I have come across.

I wonder though if you could answer a question, and this probably is a n00b question but I've been unable to find an answer either here or by searching Google. I am struggling to figure out the difference between using a render array and using a theme function - apart from some variations in syntax, they both seem to take arrays and produce html output, of course with themes you have the added advantage of being able to use tpl.php files, so why bother with render arrays at all?? Why not just theme everything? As far as I can see both still allow either themes or other modules to alter the data before final rendering??

Very confused by these....


Last seen: 10 years 41 weeks ago
Joined: 2011-05-19
I am also a beginner, but

I am also a beginner, but this is how much I understand...

Whether you use render arrays (they are just plain associative arrays) or you just theme your data right on the spot give the same result. But the output of a theme function is an html string, which other modules can not modify.

Render arrays on the hand allow for great flexibility. Other modules (through hooks) can change the render arrays before they are themed...simply by implementing the right hook and changing any properties in there.

Watch this video that shows how changes are made to a render array:

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:

Contact us

Below are the supported keyboard shortcuts for our video player.

Start / stop video
Go to next video
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
Jump to a percentage (2 is 20%, for example)
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
1 month
6 months
10% off
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.