Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of importing Resource Files into ThinkPHP template engine

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "ThinkPHP template engine import resource file method", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "ThinkPHP template engine import resource file method"!

Generally speaking, the traditional way to import external JS and CSS resource files is to use directly in the template file:

ThinkPHP's template engine provides special tags to simplify the above imports.

1. import label

The first is the import tag, imported in a namespace similar to ThinkPHP's import function, for example:

The Type attribute defaults to js, so the following effects are the same:

It can also support batch import of multiple files, such as:

To import an external CSS file, you must specify a value for the type attribute, for example:

The default import starting path is the Public directory under the root directory of the website. If you need to specify other directories, you can use the basepath attribute, for example:

If the imported file contains ". ", you can use:

The requested URL/Public/Js/Util/Array.min.js was not found on this server.

It also supports importing version numbers of resource files, such as:

It is also possible to import multiple files.

The improt tag supports load judgment. For example, the following first judges whether the name variable is set:

Or more complex, even with the function:

The compiled template cache is:

2.load label

The second is the load tag, which imports the public JS or CSS of the current project by URL, for example:

Special template tags can be substituted in the href attribute, for example:

Load tag does not need to specify the type attribute, the system will automatically determine according to the suffix.

Of course, the load tag also supports conditional calls:

The system also provides two tag aliases, js and css, whose usage is consistent with load, for example:

The load tag also supports importing multiple resource files at the same time, even different types of resource files:

At this point, I believe that we have a deeper understanding of the "ThinkPHP template engine import resource file method," may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report