Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write a Smarty plug-in to load data directly in a template

Shulou Source: shulou.com Published: 2022-06-03 06:39:10 10月04日 Update

This article mainly shows you "how to write Smarty plug-ins to load data directly in the template", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "how to write Smarty plug-ins to load data directly in the template" this article.

In the past, when using smarty, you usually read the data on the php program side (usually from the database), and then assign the variable to the template before you can use this variable on the front end. This is not bad, but it is a bit troublesome to maintain the php code when there is a lot of data, especially when there are a lot of template blocks of data.

So write a plug-in, combined with the previous crud class implementation in the front-end template can load some modular data.

The code is as follows:

In addition to reducing a lot of maintenance, writing a plug-in has a significant advantage that you can uniformly format and filter operations that query the database in this plug-in.

So that the data can be loaded like this at the front end:

The copy code is as follows:

{load_data assign= "list" table= "test" where= "`id`

Tags: Data plug-ins templates code front end variables content articles databases time learning help significant bad just advantage that is easy to understand is in more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Huawei vpn NVidia Linux