ThinkPHP custom template tag details-PHP development

Source: Internet
Author: User
Through the above comparison, it seems that ThinkPHP's Custom template tag calls are much simpler than phpcmsv9 labels, but phpcmsv9 features are not flexible and powerful, which requires the participation and improvement of many tper. Summary: The ThinkPHP custom template tag can be called in different templates of the same project, which is convenient and simple, but it only takes some effort to define the tag library. Template tags make website front-end development faster and simpler, which makes the work that should have been done by programmers. Now, only people who know HTM can easily do it, this is the strength of the template tag. Anyone who has been familiar with dedecms, phpcms, and other content management systems knows that the front-end of cms uses template tags to call data, such as lists and content. Let's take a look at the label of the Data ranking list called by phpcms v9:

{pc:content action="hits" catid="6" num="10" order="views DESC"}     {loop $data $r}       
  • {$r[title]}
  • {/loop}{/pc}

    Note:

    The parameter format of the pc braces is:

    {Pc: content parameter = "parameter value" parameter name = "parameter value "}

    Action: The value of this parameter indicates an operation event. The model PC label must contain this parameter to describe the operation to be performed.

    Catid: gets the ID of the channel column and the data of the column.

    Num: gets the number of records, and is finally transferred to the processing function by the template engine as limit.

    Order: indicates the sorting method of the Data list.


    The preceding phpcms template module obtains 10 data records of Columns with ID 6 and sorts the data by clicks.


    However, since PHPCMS V9 is already a mature CMS, its template labels are already defined, such as "pc" and "num" tags, we can only read the PHPCMS V9 user documentation to learn how to call it, but cannot change its name. ThinkPHP is just a framework, each developer can use custom template tags to simplify data calling methods.

    The following is a ThinkPHP template tag to define such a function:

    1. Obtain the number of records, similar to the "num" in phpcms v9 above"

    2. Sort data


    Preparations: first find a ThinkPHP CMS or blog program without a custom template tag to install it. For ease of instruction, I will use wblog3.1.3

    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.