Home Backend Development PHP Tutorial Thinkphp5 custom tags

Thinkphp5 custom tags

Jun 01, 2018 am 09:19 AM
php thinkphp5 customize

This article mainly introduces the custom tags of Thinkphp5, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

Thinkphp5 custom tags:

1. The method name of the custom tag:

The form is: if the tag name is jquery, then its corresponding tag implementation function is tagJquery() (note that tag is prefixed and written in camel case)

1. Steps:

1) Create the Mytag.php file (note the namespace)

Create the My.php file: path application/common/ taglib/My.php

2) Declare namespace:
namespace app\common\taglib

#use think\template\Taglib  

      3), Define Class


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

class My extends Tagelib{

                 protected $tags=array(

                 'jquery'=>array('','close'=>0),       

                 'webuploaderjs'=>array('','close'=>0),

            );

             

             /**

                 * jquery

                     */

                 public function tagJquery(){

                $str=<<<php

               <script src="__STATIC__/js/jquery.js"></script>

            php;

                    return $str;

                 }

           }

Copy after login

        4), Configure


1

2

3

4

application/config.php

           'template'               => [

                     'taglib_pre_load' => 'app\common\taglib\My'

             ],

Copy after login

          5), The use of custom tags in pages

1

2

    {my:jquery/}

//这样就把jquery引入到了页面模板中

Copy after login

The above is the entire content of this article, thank you for reading. Please pay attention to the PHP Chinese website for more information!

Related recommendations:

Detailed explanation of ThinkPHP5.0 framework controller inheritance base and custom class cases

Thinkphp5 behavior usage summary

The above is the detailed content of Thinkphp5 custom tags. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles