Using custom plug-ins in smarty to load data (see the detailed introduction of writing a smarty plug-in to directly load data in the template), it is not convenient to use it, just like the foreach Tag:
Step 1: Add the following in the _ compile_tag function of smarty_compiler.class.php:
CopyCodeThe Code is as follows: // The start label for loading data
Case 'load ':
$ This-> _ push_tag ('load ');
Return $ this-> _ complie_load_start ($ tag_args );
Break;
// Load the end tag of the data
Case '/load ':
$ This-> _ pop_tag ('load ');
Return "<? PHP endforeach; endif; unset (/$ _ from);?> ";
Break;
Step 2: Add a method:
Copy codeThe Code is as follows :/**
* Load data
* @ Param $ tag_args
*/
Function _ complie_load_start ($ tag_args)
{
$ Key = substr (MD5 ($ tag_args), 8, 16); // generate a special variable name based on the parameter
$ Attrs = $ this-> _ parse_attrs ($ tag_args );
// More processing can be added here
$ Class = (! Isset ($ attrs ['class']) | empty ($ attrs ['class'])? 'Cls _ crud ': trim ($ attrs ['class']);
(! Isset ($ attrs ['table']) | empty ($ attrs ['table']) & Exit ('table' is empty! ');
$ Db = $ class: Factory (Array ('table' => substr ($ attrs ['table'], 1,-1 )));
// Define new variables
$ This-> _ tpl_vars [$ key] = $ db-> get_block_list (Array (substr ($ attrs ['where'], 1,-1 )), $ attrs ['limit']);
$ Tag_args = "from =/$ {$ key}". $ tag_args;
// Call the foreach tag processing function for processing
Return $ this-> _ compile_foreach_start ($ tag_args );
}
In this way, you can use the load label in the template. Example:Copy codeCode: {load table = "test" where = "'id' <100" Limit = 10 item = rec}
...
{/Load}