WebsiteBaker Support (2.8.x) > Templates, Menus & Design

The template object

(1/2) > >>

iceat:
For a module i'm building i made a template file with 3 parts:

1. opening html (eg. opening a table)
2. a part that needs to be repeated based on the result of a query (eg. tablerows)
3. closing html (eg. closing the table)

Is it possible to repeat a part of the template before? When I look at the code of "pages" in wb, the repeating part is done with html code in the code (spaghetti code). I want to separate these.

doc:
Hi,

you can seperate HTML and PHP e.g. by the use of a template engines (phplib, or any other available lib).

Doc

iceat:
Here's how I did it

The template looks like this:

--- Code: ---
<!-- BEGIN main_block -->

<!-- BEGIN folderlist_start -->
<table border="0" cellspacing="1" cellpadding="0" width="100%" class="tblMatrix">
    <tr>
        <td class="tblHeader" colspan="2">
            Folders
        </td>
    </tr>
<!-- END folderlist_start -->

<!-- BEGIN folderlist_repeat -->
    <tr>
        <td class='tblBody'>
            <a href='?tool=obotra&folder={FOLDER_ID}'>{FOLDER_NAME}</a>
        </td>
        <td class='tblBody' width='90'>
         {FOLDER_ACTIONS}
        </td>
    </tr>
<!-- END folderlist_repeat -->

<!-- BEGIN folderlist_stop -->
</table>
<br />
<a href="?tool=obotra&folder={FOLDER_ID}&action=addfolder">Add folder</a>
<!-- END folderlist_stop -->

<!-- END main_block -->


--- End code ---

The code looks like this:

--- Code: --- function parse_folderlist(){

$template = new Template(WB_PATH.'/modules/obotra/template');
$template->set_file('page', 'folders.html');
$template->set_block('page', 'main_block', 'main');
$template->set_block('main_block', 'folderlist_start', 'folders');
$template->set_block('main_block', 'folderlist_repeat', 'folders');
$template->set_block('main_block', 'folderlist_stop', 'folders');

$template->set_var('FOLDER_ID',  $this->current_id);
$template->parse('main_block', 'folderlist_start', true);


foreach ($this->folders as $f){

$template->set_var('FOLDER_ID',  $f[0]);
$template->set_var('FOLDER_NAME',  $f[1]);
$template->parse('main_block', "folderlist_repeat", true);
}

$template->parse('main_block', 'folderlist_stop', true);

$template->parse('main', 'main_block', false);
$template->pparse('output', 'page');

}

--- End code ---

The html is completely in a separate file. This way of working should also be used when parsing the page-table in the backend.

PurpleEdge:
That's interesting, if you get the time can you upload a template that uses this technique?

iceat:
this is atm only for module (backend and frontend) templates, if you want some more explanation about this, let me know and i'll try to document it.

The great thing about this is that you can deliver a standard template with your modules in the module directory but you can scan the template directory for possible overwrites. It's always a good thing to keep designers away from your code :) New modules should be built with this in mind.

Navigation

[0] Message Index

[#] Next page

Go to full version