What are your templating strategies?

后端 未结 5 529
感情败类
感情败类 2020-12-16 07:36

I try to develop my own little framework. For this, I\'d like to read up some templating techniques. I know that templating is a really complex topic, but knowing some strat

5条回答
  •  长情又很酷
    2020-12-16 07:45

    My strategy is as follows:

    1. Try and use the minimum of PHP in the template and if possible down to none.
    2. I have created classes for various components commonly found in web pages, one of them is tpanel which I am using to demonstrate the concept below
    3. tpanel for example would handle all the logic to create a menu, parses a small template for 'navigation_menu' and sends the result for final inclusion to overall template.

    Effectively I am creating 'blocks', very similar to what Drupal does - if you are familiar with it.

            $this->load->library('tpanel');
            $s=$this->tpanel->get('date',$data);
            $s.=$this->tpanel->get('navigation_menu',$data);
            $s.=$this->tpanel->get('ajax_menu',$data);
            $s.=$this->tpanel->get('spacer',$data);
            $data['title']='List of Databases';
            $post=$this->uri->segment(5);
            $blog=(file_get_contents('../'.$dir.'/'.$post.'.dat'));
            $s.=markdown($blog);
            $data['content']=$s;
            $view='/admin/admin_simple_view';
    

    The system is much more flexible that what I have shown above. For example the tpanel->get('ajax_menu, $data) also handles the script settings using jQuery.

    I have been also looking at Django lately and they have some very good ideas on templating. It might be worth getting a look, even if you are not a Python programmer, especially how they handle inheritance.

提交回复
热议问题