The template object

PurpleEdge

I think I'd learn more by looking at a complete module that can be used with an existing site - I'm not sure what the code you posted actually does, or if it can be used on any site? If you can post even a simple module that would be a big help to me.

I agree with you that most modules use spaghetti code that is difficult to write and maintain. Most alternatives to WB (eg Concrete5 and ModX) have moved away from this style of code and if you have a better technique for WB, then I'm interested!

Thanks

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.
Webdesign/-Development, Freelance

> [url="http://www.medialoft.be"]http://www.medialoft.be[/url]

PurpleEdge

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

iceat

#3
Here's how I did it

The template looks like this:


<!-- 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 -->



The code looks like this:

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');

}


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

> [url="http://www.medialoft.be"]http://www.medialoft.be[/url]

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

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.
Webdesign/-Development, Freelance

> [url="http://www.medialoft.be"]http://www.medialoft.be[/url]