CodeX
CodeX

Reputation: 313

Block positioning using admin section

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:

enter image description here

Is there a simpler way?

Upvotes: 2

Views: 96

Answers (1)

xDaevax
xDaevax

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:

  • You are creating a type of CMS application used to create websites
  • The websites are modular and will allow administrators to easily customize both the look and feel of their website and the content, without having extensive code knowledge
  • To facilitate this, you've created a system of templates, and content, that can be combined in various ways to create these themed pages. This is driven primarily by a set of PHP functions that extract the template and block data from the DB.
  • As new themes are created, the admin is able to "just work" without any modification because the functions can pull in any theme and it can be combined with any template.
  • The templates will have to have a naming structure that is generic so that CSS can be easily swapped out.

Given this information, I would suggets doing the following:

Database Schema

I would set up a database structure to something that resembles this schema I made:

enter image description here

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.

DB Conclusion

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.

PHP Admin

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:

  1. Log in to admin
  2. Select Operation (a-> Create New, b-> Update Existing)
  3. Select Page Template
  4. Assign content blocks to template slots
  5. Preview
  6. Compile changes (a -> Save New Page, b-> Update Existing)

Upvotes: 2

Related Questions