码迷,mamicode.com
首页 > 其他好文 > 详细

Helpers\Assets

时间:2016-07-05 13:45:36      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

Helpers\Assets

The assets helper is for loading CSS and JS files rather than writing out the full script/link tag for each and every item, instead add them to an array pass to the assets and it output the link/script tags for you.

Usage example for loading CSS files:

Assets::css([
    ‘https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css‘,
    Url::templatePath().‘css/style.css‘,
]);

Will output:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="http://novaframework.dev:8888/templates/default/assets/css/style.css" rel="stylesheet" type="text/css">

Assets has 2 methods css and js, they can take a single value or an array of values.

Example of loading a single js file:

Assets::js(Url::templatePath().‘css/app.js‘);

Both methods have additional parameters other than the file/s:

$cache Default set to false, when set to true the contents will be compressed and compiled into a single files placed within your theme css/js folder.

$refresh Default set to false, set to true to update the cache.

$cachedMins Time in seconds to hold the cache.

Example using a cache:

Assets::css([
    ‘https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css‘,
    Url::templatePath().‘css/style.css‘,
], true);

Example using a cache and refresh:

Assets::css([
    ‘https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css‘,
    Url::templatePath().‘css/style.css‘,
], true, true);

Helpers\Assets

标签:

原文地址:http://www.cnblogs.com/chunguang/p/5643104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!