Reputation: 313
In my admin section i have a block maker. The block is very simple, block_title, block_content.
What is the simplest way to show / determine a themes layout in the admin section so the user can position the blocks?
One idea is to use numbers so, 1 = block area one, 2 = block area two etc
A function in the front end could look like this:
function showBlocksForArea(1) {
// Return blocks Array where block_area=1
}
Rendered in the theme / template as:
echo'<div id="block_area_one">';
foreach($view->showBlocksForArea(1) as $row) {
echo '
<div class="block_wrap">
<div class="block_title">'.$row['block_title'].'</div>
<div class="block_body">'.$row['block_body'].'</div>
</div>
';
}
echo '</div>';
This is fine, accept the user doesn't know without looking at the theme where those areas are.
The Admin Section
Something like this would be perfect if i could grab just the HTML of the layout:
Is there a simpler way?
Upvotes: 2
Views: 96
Reputation: 2022
The following is an answer based on the chat that occurred here: https://chat.stackexchange.com/rooms/18020/room-for-xdaevax-and-codex
Here is my understanding of your goals:
Given this information, I would suggets doing the following:
I would set up a database structure to something that resembles this schema I made:
The idea here is that a Template
record can have any number of "slots". The DB is agnostic in terms of where the slots go on the page (this is the responsibility of the theme), but the TemplateSlots
are used to provide "place holders" for where content (Blocks
) can be placed.
Each time a user creates a new Page
, a Page record is added and the page is associated with a Template
, from which it also has information about the slots. The Template
also defines a file (a PHP file most likely) that specifies place holders where the slots are placed. The Page gets the Theme
information from the Site
which it is associated with. Each Theme
can have a set of ThemeContents
(multiple CSS files, js files, images, etc....).
Blocks
can be created that could have content assigned to them. These blocks are independent of a Template
initially, and the DB could be pre-populated with common building 'blocks'. These blocks can be associated with a Template
and assigned a TemplateSlot
once a block is assigned to a Page
by having a PageBlock
record created.
This structure allows a great deal of flexibility and allows the Database to handle many potentially complex user scenarios. By segmenting the Template and Slots into separate tables, you can dynamically create templates of all shapes and sizes without having to make any code changes.
For your admin, you can use whatever mechanism you like to pull the data out of the DB. But the user workflow would look something like this:
Upvotes: 2