We’ve had a couple of discussions recently with people trying to understand the data structure of Coaster and more specifically, where data is stored in Coaster CMS and I thought I’d summarise some of the points we’ve replied with here.
It’s worth remembering this about Coaster’s structure…
“Blocks can be either global (with the potential to appear on any template) or template specific”
So, you’ve uploaded an image to Coaster on a repeater or onto a page and as a developer you want to know… “where has that data actually gone?”
Where data is stored in Coaster CMS
Ok, so the actual data is stored in either page_blocks, page_blocks_default (global) or page_blocks_repeater_data (repeater data)
More complex block data is stored as a serialised object (for example images have an alt attribute and a file path attribute).
In the case of a repeater, the data structure and reasoning is as follows:
- Repeaters are blocks within blocks to create “repeatable” content. The repeaters are defined in blocks then blocks_repeaters.
- The page_block table stores which repeater is being used on which page (so same repeater can be used anywhere)
- Then there is a page_block_repeater_rows table which tells the system how many instances of each repeater row there are.
- The data (page_block_repeater_data) then contains multiple data points for the row – a value that is the sort order of the repeater and the data for each block in that repeater instance
When you use {!! PageBuilder::block(‘block_name’) !!} the system gets the block id by looking in the blocks table and knows the page from the URL then it gets the block data from the above tables and passes it to the block’s display function in Libraries/Blocks/[BlockType].php.
Hopefully, this makes some sense of the structure behind Coaster and also gives you an idea of how powerful it can be (especially in terms of repeating content).