[eluser]Yorick Peterse[/eluser]
After a bit of thinking about a way to style
all modules without having to define
any HTML or PHP in the module view itself, I came up with the following idea.
Each module uses the exact same skeleton. This skeleton file can be seen as a template for each module, but without having to make a new template for each module all modules will simply rely upon the same file.
Whenever a certain module is being loaded it will call this skeleton file, which is stored in the user's template, and load it. The skeleton file will define the structure of the content, PyroCMS will only output the raw content. To clarify my idea I created the following skeleton structure :
Code:
<!-- Module title -->
<h3 id="module_title">{MODULE TITLE}</h3>
<!-- Module container -->
<div id="module_container">
<!-- foreach(.....): -->
<!-- Module item -->
<div class="module_item">
<!-- Item heading -->
<div class="item_heading">
<h4>{ITEM TITLE}</h4>
<p>{ITEM EXTRA}</p>
</div>
<!-- Item body -->
<div class="item_body">
{ITEM BODY}
</div>
<!-- Item bottom -->
<div class="item_bottom">
{ITEM BOTTOM}
</div>
</div>
<!-- endforeach; -->
</div>
Example
Imagine we have a template called "beer_template", and the skeleton file is called "module.php". Our template's file structure could look like the following :
Code:
themes
|
|
|_beer_template
|
|
|
|_css
| |
| |_reset.css
| |_style.css
|
|
|_img
| |
| |_example.jpg
|
|
|_layout
|
|_default.php
|_default_wide.php
|_module.php
When PyroCMS loads a certain module it will send the array "$modules" to the module.php, this array will contain the data required for the module. It will also send the variable "$module_name" to the module.php file. In a typical scenario your module.php file will look like the following :
Code:
<!-- Module title -->
<h3 id="module_title"><?php echo $module_name; ?></h3>
<!-- Module container -->
<div id="module_container module_<?php echo $module_name; ?>">
<?php foreach($modules as $module): ?>
<!-- Module item -->
<div class="module_item">
<!-- Item heading -->
<div class="item_heading">
<h4><?php echo $module['item_name']; ?></h4>
<p><?php echo $module['some_extra_stuff']; ?></p>
</div>
<!-- Item body -->
<div class="item_body">
<?php echo $module['body'];?>
</div>
<?php if($module['has_bottom'] == true): ?>
<!-- Item bottom -->
<div class="item_bottom">
<?php echo $module['bottom']; ?>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
All the other stuff, such as archives or categories should be placed in the sidebar.
Using this structure will give the user full control over the layout of his template, without having to add a seperate PHP file for every module.