How to structure your site


Drupal has content types, fields, field collections, views, relations, filters.... For a complex site it is a challenge to find the right structure.

The exercise we are going to make reminds me of the 'normalisation' of databases. Indeed, databases and their structure are so Drupal. Drupal has his own database structure where content types are tables and fields just database fields. Views are written in SQL, the Structured Query Language. You can even make this query visible in views, by the way.

I am going to handle this subject with an example: Music albums.

Eg. Abbey Road from the Beatles has songs as 'Here comes the sun' and 'Her Majesty'.

First you make a structure without the fields. You do it Top-down or Buttom-up. An album is being made by a group and contains many songs. A group is a collection of artists.


You have 4 content types: Album, songs, groups and artists. First you make artists and through reference you add them to a group. then you make the content type 'songs' and finally the content ype Albums referring to the songs and the group. the fields are logic. A birthday of an artist belongs to the artist, the year of release of the album stays with the album. Done...

What can one expect from this structure?  Do we know who played in a song? NO! In this structure, every song is connected to the entire group. We need to get rid of the group as a reference towards the artists.


This structure allows us to select the artists who participated to this song. More work has to be done... but it suits our goals..


The group content type with all the information needs to have a reference, but where? Album... could be, but some albums are compilations of many groups. It is better to reference this in the song content type. Each song can have a different group. If their is only one person, then the group and the artist are the same.



Now we want to know who played, which instrument, in a particular song.

Paul McCartney can sing and plays gitar, but he doesn't sing in each song...So whe have to refer to 2 fields at the same time. Not only the artist, but also his function in the song. They are connected. This is where field collection appears. We make a field collection 'performers' with the 2 fields: artist and his/her function.



Our main structure is ready. Now we have to fill in the fields.

The Artists


The field collection: 'Performance'


The songs. I remind you that the field collection refers to 2 fields at the same time. Mind the reference towards the group.


The albums. Add a multiple song field. By referring to the songs, you immediately import the artist and their function.


Now you have to make the view with relations to connect the content types.


You see that some relations are built on other relations. Logic... You have 4 levels, so you need 3 relations. Only the highest content type needs no relation.



Adding relations to a view makes the field content repeating. You see for every song the album title, picture, body. this is normal. You can solve this problem by grouping the fields.



The best way of structuring your site does not exist. It depends on what you need to see. Make a drawing on paper before you start with your site. Then you go top-down or bottum-up. With bottum-up you inherit all the content. Sometimes this is not needed, so you have to adjust your fields. This creates more work inputting more fields.

You need relations to make the views. Do not go further than 3 relation levels. It slows down your view and it makes it very complex. When speed is needed you can turn back tot the Middle Ages and make a content type close to the view you want. In this content type you use only one reference level. All fields are direct fields. Eg. song 1 has artist 1 a; artist 1 b,.. song 2 has artist 2 a, artist 2b,... A lot of fields and not flexible. You can not add more artists than the fields you prepared. But the structure is very simple. A lot of work, but not difficult... Not the Drupal way though...