I found an answer for my question:
http://www.techfounder.net/2008/11/18/oo-php-templating/

I think this is the best way to make an easy templating class.


And if I want the user to create templates without PHP (with placeholder) I
think I'll write a TemplateCompiler from placeholderTemplate to PHP
Template. This class could also use an Optimizer class to fasten the
template code.


Matthias W. wrote:
> 
> Hi,
> I'm going to implement a CMS.
> The first classes are created and now I'm on the menu.
> 
> The menu should contain a template so that I only have to create an array
> with the menu structure and a template with the HTML.
> 
> 
> I've got:
> $tmpl = array(
>   'navigationClassCSS' => 'nav',
>   'menu' => array(
>         array(
>                 'link' => 'http://...',
>                 'name' => 'Linkname',
>                 'submenu' => array(
>                         array(
>                                 'link' => 'http://...',
>                                 'name' => 'Linkname',
>                         ),
>                         array(
>                                 'link' => 'http://...',
>                                 'name' => 'Linkname',
>                         ),
>                     ),
>         ),
>         array(
>                 'link' => 'http://...',
>                 'name' => 'Linkname',
>         ),
>     ),
> );
> 
> Template:
> <ul class="<?=$tmpl['navigationClass'] ?>">
>       <?php foreach($tmpl['menu'] as $links) { ?>
>       <li>
>               <a href="<?=$links['link'] ?>">
>                       <?=$links['name'] ?>
>               </a>
>               <?php if (isset($links['submenu'])) { ?>
>                       <?php foreach($tmpl['submenu'] as $subLinks) { ?>
>                               <li>
>                                       <a href="<?=$subLinks['link'] 
> ?>">
>                                               <?=$subLinks['name'] ?>
>                                       </a>
>                               </li>
>                       <?php } ?>
>               <?php } ?>
>       </li>
>       <?php } ?>
> </ul>
> 
> 
> And till now I include the template with:
> 
> include 'template.phtml';
> 
> But I think this is no proper way to include the template.
> I want it the following way:
> 
> $template = new Template('filename.phtml', $tmpl); //$tmpl is the array
> with the placeholders
> echo $template->get(); //get the completed HTML from template
> 
> Also I thought about a custom placeholder replacer to use a templates like
> this:
> <ul class="[[navigationClass]]">
>       [[foreach|menu]]
>       <li>
>               <a href="[[menu:link]]">
>                       [[menu:name]]
>               </a>
>               [[if|menu:submenu]]
>                       [[foreach|menu:submenu]]
>                               <li>
>                                       <a href="[[menu:submenu:link]]">
>                                               [[menu:submenu:name]]
>                                       </a>
>                               </li>
>                       [[/foreach|menu:submenu]]
>               [[/if|submenu]]
>       </li>
>       [[/foreach|menu]]
> </ul>
> 
> 
> How can I do this?
> 
> I dont want to use TemplateSystems like Smarty, because I want to keep it
> really simple.
> 
> I also thought about 'compiling' the templates to reset the
> [[placeholders]] with php-code -> I've got template.tpl which will be
> compiled to template.phtml. But I think this isn't that good.
> 

-- 
View this message in context: 
http://www.nabble.com/Menu-Templating-tp22368087p22368363.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to