PHP development essential PHP template engine Dwoo deep learning

Source: Internet
Author: User
Tags php template
[IT168] in the previous tutorial on Dwoo (step-by-step learning of the PHP template engine Dwoo is essential for PHP development), we discussed the basic usage of Dwoo. In this article, we will further explain some advanced usage in Dwoo, such as writing plug-in mechanisms and integrating with common PHP frameworks. 1. Inheritance of templates in Dwoo "> <LINKhref =" ht

 

[IT168] in the previous tutorial on Dwoo (step-by-step learning of the PHP template engine Dwoo is essential for PHP development), we discussed the basic usage of Dwoo. In this article, we will further explain some advanced usage in Dwoo, such as writing plug-in mechanisms and integrating with common PHP frameworks.

1. Inheritance of templates in Dwoo

One of the powerful functions of Dwoo is that it supports inheritance of templates. This implementation is very simple. you only need to define a parent template, and then the child template can inherit the parent template, and you can define multiple new features in the child template. Smart developers will be good at using this feature to reduce repetitive work.

In Dwoo, the key to inheriting a template is the "extension" plug-in mechanism, which allows the template to inherit another template. To better understand this feature, we will give an example as follows. Suppose you already have a base class template named base. tpl, which contains two areas: a navigation area and a content area, as shown below:





{Block "nav "}
{/Block}
{Block "content "}


This is content for the main page.

{/Block}

 

Now, if you want to use horizontal navigation bars for some of your pages, you only need to inherit the base class template page, and you can redefine the style of the navigation bar, as shown in the following code, we define this code as child. tpl:



{Extends "base. tpl "}
{Block "nav "}


Home |
News |
Weather |
Hotels |
Dining


{/Block}

{Extends "base. tpl "} indicates that it inherits the template of the parent class and overwrites the content of the navigation bar in the {block" nav "} Area. the output is as follows:

  

Now let's look at another situation. assume that some pages require additional sub-navigation menus. for example, to display the navigation bar vertically, we can use the following code:

Extends "child. tpl "}

{Block "nav "}
{$ Dwoo. parent}


{$ Subtitle}



    {Loop $ items}
  • {$ Item}

  • {/Loop}


{/Block}

{Block "content "}

This is content for the Dining page.

{/Block}

{$ Dwoo. parent} calls the parent class template. Note that child is inherited here. the tpl template, that is, the content in the navigation bar of the parent class template is called, and a vertical navigation bar is redefined here. Note that the content area is also rewritten here, the content of the content area in the parent template is overwritten. The result is as follows:

  

As you can see, as long as the appropriate use of template inheritance, it is much easier to develop.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.