Home > WeChat Applet > Mini Program Development > WeChat Mini Program: Use of Style Templates

WeChat Mini Program: Use of Style Templates

高洛峰
Release: 2017-03-01 11:06:29
Original
2968 people have browsed it

In the development process of small programs, we are likely to encounter the situation where the partial layout codes of multiple pages are the same. There may be many repeated styles between interfaces. However, the codes of these styles must be updated every time. Rewriting is very troublesome and wastes resources. WeChat applet, like other developments, also has the use of style templates. What we are going to introduce today is how to use style templates (include and import).

1. Use include to include template styles
For example: First we need to create a folder to store style templates, we Take the text component template as an example:

WeChat Mini Program: Use of Style Templates

Then we use to import in the page that needs to reference the modified template. That’s it. We can see that the display result is as shown below:

WeChat Mini Program: Use of Style Templates

Using this method to reference the template is actually equivalent to copying all the header code in templates to include.


2. Use the import method to reference the template

<!--模板样式的使用  底部样式-->
<import src="../templates/footer"  />
<template is="footer1" />
Copy after login

Similarly, we create a footer.wxml under templates, and we create two bottom layouts with the following code

<template name="footer1">
51小程序-底部布局1
</template>

<template name="footer2">
51小程序-底部布局2
</template>
Copy after login

WeChat Mini Program: Use of Style Templates

The method for us to import these two bottom styles in the newvip.wxml page is as follows (because there are two styles, we need to use template is to specify which style to use)

<!--模板样式的使用,底部样式-->
<import src="../templates/footer" />
<template is="footer1" />
<!--模板样式的使用,底部样式-->
<import src="../templates/footer" />
<template is="footer2" />
Copy after login

The results after debugging and running are as follows:

WeChat Mini Program: Use of Style Templates

Summary:
1. Calling through include is equivalent to all the contents of the called file. Copy it in.
2.Import needs to use is to declare which style to call, instead of copying all

Notes in this section:

1.There is /## at the end

#2.There should also be /

at the end. For more WeChat mini programs: related articles on the use of style templates, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template