PHPDevShell Templates and Typography
2010-01-25 22:58:35   来源:   评论:0 点击:

PHPDevShell Template and Typography System

Fig 1 Template System

PHPDevShell uses the Smarty template system to split code and html. However, PHPDevShell takes it much further then this. PHPDevShell template system has an outer or main template system handling mostly the look and feel of pages (Fig 1). Then it has a inner or script layout template system which is handled by Smarty. It does not stop there however, each script can be linked to unlimited virtual menus, allowing you to not just have multiple outer template look and feel for each script but also multiple inner script layout.

This means that the same script can look completely different depending on the needs. For instance if you have the same application for multiple companies not only can you control their design but also have the script layout exactly like they want to, and this all from a single php script.

How it works

Each script can be assigned with a main outer template handling the look and feel of the overall script and then a layout template. This can be done in the template management or when in your plugin configuration installation script.

The main template

The main outer template can be found under templates/ this folder contains all the templates required. One template can be used here to handle all your scripts. You could also assign multiple scripts different main templates for different companies for instance. The outer template system is very easy to mock up, the default templates is a good starting point though.

The script layout

The script layout offers multiple or single layout by passing it to the Smarty template system. You can create virtual (symlink) menu items to original scripts and assign different layout templates if multiple layouts is required, for instance, where you want to make the login screen look completely different.

The system will by default use the same name as your php script within the plugins/yourplugin/templates folder.

For example (See simplephonebook plugin for examples);

plugins/SimplePhonebook/myscript.php
// Will use smarty template...
plugins/SimplePhonebook/templates/myscript.tpl

Please see Smarty to understand easy Smarty syntax.

To Pass data to your template

Passing data to a template from your PHP script is easy (plugins/SimplePhonebook/myscript.php).

// ...php code...
 
// Generally the assignment of the scripts should be last.
// Set variables.
$this->template->set('my_foo', "Passing information to smarty.");
$this->template->set('my_bar', "Passing more information to smarty.");
// We now call our template.
$this->template->show();

Now lets receive the data in our Smarty template (plugins/SimplePhonebook/templates/myscript.tpl).

<tr>
    <th>
        {$my_foo}
    </th>
    <td>
        {$my_bar}
    </td>
</tr>

Typography

Script heading and information

It is a good practice to always add a heading and information about your script to be nicely displayed to give the user information on where they are. To do this in PHPDevShell you will use (inside php script):

// Some information to the user about my script.
$this->template->heading("My Useless Script");
$this->template->info("This is my script it is suppose to be useless for your enjoyment.");
//...continue with code...

Information and Logging

PHPDevShell comes with multiple methods to show the user what is going on and what just happened, like when a user saves a page, you would in a neat fashion show him "Your data was saved." for instance. The notification methods also logs information as it happens, "Your data was saved." is now also logged for the admin to see what happened and when it happened.

// Methods with auto logging.
warning ($warning, $return = false, $log = true);
critical ($critical, $return = false, $log = true);
ok ($ok, $return = false, $log = true);
// Usage...
$error = true;
 
if ($error == true) {
    $this->template->warning('No, what have you done you stupid idiot, you missed some fields.');
} else {
    $this->template->ok('Nice, I managed to save the data. BTW, how is your mama!');
}
 
// Methods without auto logging.
notice ($notice, $return = false);
busy ($busy_note, $return = false);
message ($message_note, $return = false);
note ($note, $return = false);

More documentation will follow soon

  • ->template
    • hook ($hook_point_id)
    • scripthead ($scripthead, $return = false)
    • icon ($icons)
    • iconize ($img,$text)
    • info_mark ($info_mark, $print = false)
    • out ($variable)
    • alt_color ($alt)
    • random_color ($id)
    • html_entity_decode ($string_to_decode)
    • _i To be used inside .tpl files.
 

相关热词搜索:

上一篇:PHPDevShell Utilities
下一篇:PHPDevShell Template modules

分享到: 收藏
频道总排行
频道本月排行