NoPic eZine
  
Home
Impressum/Imprint
Datenschutz/Policies
 
1.Issue 2006.06/1
 1.1.phpWebSite 1.0.0RC1 released
 1.2.Installing pWS 1.0.0rc1
 1.3.Running thru install
 1.4.First anonymous touch
 1.5.Exploring fallout surface inside
 1.6.Module substitution
 1.7.Directory Tree
 1.8.Database Tables
 1.9.ReadMe summary
   Access.txt
   bbcode.txt
   Cache_Lite.txt
   Categories.txt
   Clipboard.txt
   ControlPanel.txt
   Converting_Modules.txt
   Cookie.txt
   CREDITS.txt
   Database_Class.txt
   DB_Pager.txt
   Demographics.txt
   devdoc.modlayout.txt
   Developer_Rules.txt
   Editor.txt
   Forms.txt
   INSTALL.doc.txt
   Key.txt
   Known_Errors.txt
   Language.txt
   LICENSE.txt
   MiniAdmin.txt
   Mod_Rewrite.txt
   Module_Development.txt
   My_Page.txt
   README.doc.txt
   README.txt
   Related.txt
   Search.txt
   Settings_Class.txt
   SmartTags.txt
   Style_Format.txt
   template.txt
   Theme_Creation.txt
   Using_Javascript.txt
   Version.txt
   WYSIWYG.txt
 1.10.Using module WebPages
 1.11.Using module MenuManager
 1.12.Using webPages Editor
 1.13.Styling and Themes

    en

template.txt

This is a rough draft for template. It will eventually be transfered
to an XML manual.

Templates

The fastest way to use templates are to use the process function like so:

$template = array("HEADING" => "Welcome", "CONTENT" => "This is beginning");
$module = "mymod";
$file  = "welcome.tpl";

PHPWS_Template::process($template, $module, $file);


The 'welcome.tpl' file will look something like the following:

<div class="title">{HEADING}</div>
<span class="content">{CONTENT}</span>

The template class uses the module variable to look for the template file.
It will first look in the theme (e.g. theme/mytheme/templates/mymod/welcome.tpl)
then it will look in the template directory (e.g. templetes/mymod/welcome.tpl).
Finally it will look in the mod directory itself (e.g. mod/mymod/templates/welcome.tpl).

(Note: this order may change depending on your template config file.)

The process function will return your template file with the tabs filled in.


Sometimes you may want to create your own template object. This comes in handy for
repeated rows.

Lets say the template looked like the following:

{TITLE}
<ol>
  <!-- BEGIN repeat_row -->
   <li>{NAME} {POSITION}</li>
  <!-- END repeat_row -->
</ol>
{CONCLUSION}

To have the line item repeat you would put the row array INSIDE the
row definition. 

This will repeat the 'li' line over and over within the same template.
Here is an example:

$template['TITLE'] = 'Names of Cabinet';
$template['CONCLUSION'] = 'Visit office for more information.';

$template['repeat_row'][] = array('NAME' => 'Tom Horn',
			          'POSITION' => 'President');

$template['repeat_row'][] = array('NAME' => 'Jane Plymore',
			          'POSITION' => 'Vice President');

The template class will then expect a repeated row named 'repeat_row'
and it will try to plug in the values from the array.

Note: If you are getting repeats outside of your BEGIN/END tags MAKE
SURE your tags are set properly:

<ol>
  <!-- BEGIN repeat_row-->
   <li>{NAME} {POSITION}</li>
  <!-- END repeat_row -->
</ol>

The above won't work. It's so small it is hard to notice. Look at the
BEGIN line. There isn't a space between the 'repeat_row' and the
'-->'.
One added or missing character can cause it not to work. Compare the
BEGIN and END comments character by character.


Embedded Rows
---------------------------------------------------------------------
Sometimes you will have repeat rows inside other repeated rows. This
is beyond the abilities of the above example. You will need to
instantiate a template object.

First run the constructor:

$tpl = & new PHPWS_Template($module);

Now set the file:

$result = $tpl->setFile($template_file);

The result will either be TRUE or a PHPWS_Error object.

To have the line item repeat you would use setCurrentBlock, like so:

$tpl->setCurrentBlock("repeat_row");

$tpl->setData(array('NAME'=>'Sam', 'COLOR'=>'red'));
$tpl->parseCurrentBlock();

$tpl->setData(array('NAME'=>'Ted', 'COLOR'=>'green'));
$tpl->parseCurrentBlock();

$tpl->setData(array('NAME'=>'Pat', 'COLOR'=>'blue'));
$tpl->parseCurrentBlock();

To get your data for presentation call get like so:
$content = $tpl->get();

Another hint. If you are imbedding repeating rows, the parent row must
be parsed _after_ the the child rows.

For example, lets say you want a list of families by last name. Inside,
the first names of the family members are listed. Here is what the
template may look like.

<ol>
<!-- BEGIN lastname-list -->
  <li>
    {LAST_NAME}
    <ol>
      <!-- BEGIN firstname-list -->
      <li>{FIRST_NAME}</li>
      <!-- END firstname-list -->
    </ol>
  </li>
<!-- END lastname-list -->
</ol>

Here is the code:

foreach ($families as $lastname){
  foreach ($members[$lastname] as $firstname){
    $tpl->setCurrentBlock("firstname-list");
    $tpl->setData(array("FIRST_NAME"=>$firstname));
    $tpl->parseCurrentBlock();
  }

  $tpl->setCurrentBlock("lastname-list");
  $tpl->setData(array("LAST_NAME"=>$lastname));
  $tpl->parseCurrentBlock();
}


If the lastname rows were put before the first name list, the first
names would be put under the wrong last names.

Remember to work inside to outside for order of importance.


    en

Copyright © 2006, VbID Verlagsbüro GmbH
pWS modules dcP, dcT, dc4db, Copyright © 2006, VbID Verlagsbüro GmbH
This Site is powered by phpWebSite © The Web Technology Group, Appalachian State University