在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):jenssegers/codeigniter-template-library开源软件地址(OpenSource Url):https://github.com/jenssegers/codeigniter-template-library开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):CodeIgniter Template LibraryThis template library for Codeigniter lets you build complex templates using partial views and widgets. It's built with the same method chaining support that we are seeing so often in Codeigniter so it feels familiar. This library loads a template file that uses partial views. These partial view sections are internally represented by Partial Objects managed by the template library. These objects let you modify their content in a user friendly way through method chaining. InstallationCopy the files to the corresponding folder in your application folder (or use spark). ConfigurationIn your template.php config file you can change following configuration parameters (optional):
If you prefer, you can autoload the library by adjusting your autoload.php file and add 'template' to the $autoload['libraries'] array. Template filesTemplate files are loaded or parsed by Codeigniter and the partials are passed to them as data. You can easily load them like you would normally use data in your view files:
Or when parsing is enabled you can use {content} etc. However, I prefer to directly call the library's methods from inside the template file to work around php's Undefined variable errors when you are not setting all partials. Calling these methods well replace non-existing partials with empty one's so you don't get any errors:
These variables are in fact Partial Ojects, so you can still manipulate them from inside the template view file like this:
Partial manipulation methods will always return the partial object itself for further chaining or for displaying. So this is perfectly possible:
Partial manipulationPartials have a few handy methods for manipulating their content such as:
You can also load dynamic content inside partials from view files or widgets. The object named partial used in the method chaining below is the name of the partial you want to load the content into.
Append or overwrite the partial with a view file with parameters.
Append or overwrite the partial with a parsed view file with parameters.
Append or overwrite the partial with a widget's output.
PublishingThe template class only has a few methods. I chose to do this because almost everything can be managed by using the flexible Partial Object. If you want to publish the entire template with the current partials to the output you can use the publish() method. You can pass a custom template file and optional data if wanted:
Most of the time this will be empty using the template file from the config:
If you wish to set the template file before publishing, eg. in a controller's constructor:
TriggersSome partials have built in triggers:
This is an example of what these built in triggers do:
You can set your own triggers for functions or methods for any partial object like this:
This will trigger the function or method whenever you manipulate the partial's content. WidgetWidgets are intelligent partial objects. When their content is asked, their display() method is activated which will fill the content using codeigniter or partial object methods. Widgets classes are found inside the application/widgets folder. They extend the main Widget class which has the same methods as the Partial class. This is an example widget:
And this is loaded from a controller like this:
CachingI did not want to expand the library in all different ways, therefore I implemented a basic caching function using Codeigniter's caching driver. This might slow your code down on simple websites but allows you to use caching for partials just like you would do yourself with Codeigniter's driver. You can cache particular partials:
Or you can cache all partials:
Both methods have an extra optional identification parameter that you can use to have multiple cache files for different pages:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论