Article
Posted on 14th June 2021
Takes about 3 mins to read

I'm a fan of configuring things for display through Drupal's admin UI. It gives site builders confidence and power. What if you want to place blocks or views listings in amongst fields on pages of content? For example, to display: A listing (view) of related content, such as accessories for a product A standard contact block, advert, or some other calls to action in the middle of the content, exactly where the user is best 'caught' in their journey, rather than having to stick those in sidebars or after all the content fields. Some specific value(s) pulled from fields on some indirectly related entity, through a token, such as details from a taxonomy term representing the 'section' that a page is in. Consistent relevant links on user profiles to take people to common destinations This is where the Entity Extra Field module (entity_extra_field) comes in. It supports embedding blocks, views or values to be replaced via tokens. So a site builder can set these up to be managed just like ordinary fields on the page (whether it's a node, term, paragraph, or any other type of content).

Article
Posted on 9th June 2021
Takes about 5 mins to read

Defining your own Drupal block plugins in custom code is really powerful, but sometimes you can feel limited by what those blocks have access to. Your block class is like a blank canvas that you know you'll be pulling data into, but how should you get that data from the surrounding page? Often you have to resort to fetching the entity for the current page out of its route parameters (e.g. on a node page)...

Article
Posted on 10th April 2018
Takes about 5 mins to read

Once upon a time, we wrote an article about how to render fields on their own in Drupal 7, which was really handy because Drupal 7 wasn't always intuitive. It's common to want to display a field outside of the context of its main entity page, like showing author information in a sidebar block or in a panel, but you had to just know which functions to use. Drupal 8 came along since then using...

Article
Posted on 13th January 2014
Takes about 2 mins to read

Previously on this website I have written about rendering blocks programmatically and adding things to content to be managed alongside fields. It's time to combine the two! On many projects, we find ourselves needing to render a block consistently across all content of a certain type. For example: Are you trying to place advertising blocks or fixed javascript code between the fields in the content of a page, not just shoved into regions around the...

Article
Posted on 22nd March 2012
Takes about 1 min to read

This is a real quick one, but so useful! We often want to render a block within content, perhaps as part of a node (maybe in hook_node_view, and then made configurable like a field), but there's no obvious way to do this correctly for any block. Drupal normally renders its blocks per region, so there is no single function to embed a block. I came across this really simple solution by Damien Tournoud in a...

Article
Posted on 13th February 2009
Takes about 1 min to read

We wrote an article about linking a view's block title to the companion page view, in Drupal 5. Someone asked for a Drupal 6 version, which can be quite easily done with a preprocess function, but it's not very flexible. Instead we just need to create a new display plugin for Views 2, and that will allow us to be much more flexible in our approach. This is my first display plugin, so it may...