WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.6 is now available!


Will it continue with WB? It goes on! | Geht es mit WB weiter? Es geht weiter!
https://forum.websitebaker.org/index.php/topic,32340.msg226702.html#msg226702


The forum email address board@websitebaker.org is working again
https://forum.websitebaker.org/index.php/topic,32358.0.html


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Templates, Menus & Design »
  • The template object
  • Print
Pages: [1]   Go Down

Author Topic: The template object  (Read 4871 times)

Offline iceat

  • Posts: 108
  • Gender: Male
    • Medialoft
The template object
« on: February 21, 2010, 08:20:54 PM »
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.
Logged
Webdesign/-Development, Freelance

> http://www.medialoft.be

doc

  • Guest
Re: The template object
« Reply #1 on: February 21, 2010, 08:26:02 PM »
Hi,

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

Doc
Logged

Offline iceat

  • Posts: 108
  • Gender: Male
    • Medialoft
Re: The template object
« Reply #2 on: February 21, 2010, 08:57:25 PM »
Here's how I did it

The template looks like this:
Code: [Select]

<!-- 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:
Code: [Select]
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.
« Last Edit: February 21, 2010, 08:59:54 PM by iceat »
Logged
Webdesign/-Development, Freelance

> http://www.medialoft.be

Offline PurpleEdge

  • Posts: 231
  • Gender: Male
    • the northern beaches
Re: The template object
« Reply #3 on: February 22, 2010, 03:25:38 AM »
That's interesting, if you get the time can you upload a template that uses this technique?
Logged

Offline iceat

  • Posts: 108
  • Gender: Male
    • Medialoft
Re: The template object
« Reply #4 on: February 22, 2010, 08:49:05 AM »
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.
Logged
Webdesign/-Development, Freelance

> http://www.medialoft.be

Offline PurpleEdge

  • Posts: 231
  • Gender: Male
    • the northern beaches
Re: The template object
« Reply #5 on: February 22, 2010, 02:47:51 PM »
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
Logged

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Templates, Menus & Design »
  • The template object
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2