외부 코드를 Composer 기반으로 변경
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
---
|
||||
layout: default
|
||||
permalink: extensions/asset/
|
||||
title: Asset extension
|
||||
---
|
||||
|
||||
Asset
|
||||
=====
|
||||
|
||||
The asset extension can be used to quickly create "cache busted" asset URLs in your templates. This is particularly helpful for aggressively cached files that can potentially change in the future, such as CSS files, JavaScript files and images. It works by appending the timestamp of the file's last update to its URL. For example, `/css/all.css` becomes `/css/all.1373577602.css`. As long as the file does not change, the timestamp remains the same and caching occurs. However, if the file is changed, a new URL is automatically generated with a new timestamp, and visitors receive the new file.
|
||||
|
||||
## Installing the asset extension
|
||||
|
||||
The asset extension comes packaged with Plates but is not enabled by default, as it requires extra parameters passed to it at instantiation.
|
||||
|
||||
~~~ php
|
||||
// Load asset extension
|
||||
$engine->loadExtension(new League\Plates\Extension\Asset('/path/to/public/assets/', true));
|
||||
~~~
|
||||
|
||||
The first constructor parameter is the file system path of the assets directory. The second is an optional `boolean` parameter that if set to true uses the filename caching method (ie. `file.1373577602.css`) instead of the default query string method (ie. `file.css?v=1373577602`).
|
||||
|
||||
## Filename caching
|
||||
|
||||
To make filename caching work, some URL rewriting is required:
|
||||
|
||||
### Apache example
|
||||
~~~ php
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
|
||||
</IfModule>
|
||||
~~~
|
||||
|
||||
### Nginx example
|
||||
|
||||
~~~ php
|
||||
location ~* (.+)\.(?:\d+)\.(js|css|png|jpg|jpeg|gif)$ {
|
||||
try_files $uri $1.$2;
|
||||
}
|
||||
~~~
|
||||
|
||||
## Using the asset extension
|
||||
|
||||
~~~ php
|
||||
<html>
|
||||
<head>
|
||||
<title>Asset Extension Example</title>
|
||||
<link rel="stylesheet" href="<?=$this->asset('/css/all.css')?>" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<img src="<?=$this->asset('/img/logo.png')?>">
|
||||
|
||||
</body>
|
||||
</html>
|
||||
~~~
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
---
|
||||
layout: default
|
||||
permalink: extensions/uri/
|
||||
title: URI extension
|
||||
---
|
||||
|
||||
URI
|
||||
===
|
||||
|
||||
The URI extension is designed to make URI checks within templates easier. The most common use is marking the current page in a menu as "selected". It only has one function, `uri()`, but can do a number of helpful tasks depending on the parameters passed to it.
|
||||
|
||||
## Installing the URI extension
|
||||
|
||||
The URI extension comes packaged with Plates but is not enabled by default, as it requires an extra parameter passed to it at instantiation.
|
||||
|
||||
~~~ php
|
||||
// Load URI extension using global variable
|
||||
$engine->loadExtension(new League\Plates\Extension\URI($_SERVER['PATH_INFO']));
|
||||
|
||||
// Load URI extension using a HttpFoundation's request object
|
||||
$engine->loadExtension(new League\Plates\Extension\URI($request->getPathInfo()));
|
||||
~~~
|
||||
|
||||
## URI example
|
||||
|
||||
~~~ php
|
||||
<ul>
|
||||
<li <?=$this->uri('/', 'class="selected"')?>><a href="/">Home</a></li>
|
||||
<li <?=$this->uri('/about', 'class="selected"')?>><a href="/about">About</a></li>
|
||||
<li <?=$this->uri('/products', 'class="selected"')?>><a href="/products">Products</a></li>
|
||||
<li <?=$this->uri('/contact', 'class="selected"')?>><a href="/contact">Contact</a></li>
|
||||
</ul>
|
||||
~~~
|
||||
|
||||
## Using the URI extension
|
||||
|
||||
Get the whole URI.
|
||||
|
||||
~~~ php
|
||||
<?=$this->uri()?>
|
||||
~~~
|
||||
|
||||
Get a specified segment of the URI.
|
||||
|
||||
~~~ php
|
||||
<?=$this->uri(1)?>
|
||||
~~~
|
||||
|
||||
Check if a specific segment of the URI (first parameter) equals a given string (second parameter). Returns `true` on success or `false` on failure.
|
||||
|
||||
~~~ php
|
||||
<?php if ($this->uri(1, 'home')): ?>
|
||||
~~~
|
||||
|
||||
Check if a specific segment of the URI (first parameter) equals a given string (second parameter). Returns string (third parameter) on success or `false` on failure.
|
||||
|
||||
~~~ php
|
||||
<?=$this->uri(1, 'home', 'success')?>
|
||||
~~~
|
||||
|
||||
Check if a specific segment of the URI (first parameter) equals a given string (second parameter). Returns string (third parameter) on success or string (fourth parameter) on failure.
|
||||
|
||||
~~~ php
|
||||
<?=$this->uri(1, 'home', 'success', 'fail')?>
|
||||
~~~
|
||||
|
||||
Check if a regular expression string matches the current URI. Returns `true` on success or `false` on failure.
|
||||
|
||||
~~~ php
|
||||
<?php if($this->uri('/home')): ?>
|
||||
~~~
|
||||
|
||||
Check if a regular expression string (first parameter) matches the current URI. Returns string (second parameter) on success or `false` on failure.
|
||||
|
||||
~~~ php
|
||||
<?=$this->uri('/home', 'success')?>
|
||||
~~~
|
||||
|
||||
Check if a regular expression string (first parameter) matches the current URI. Returns string (second parameter) on success or string (third parameter) on failure.
|
||||
|
||||
~~~ php
|
||||
<?=$this->uri('/home', 'success', 'fail')?>
|
||||
~~~
|
||||
Reference in New Issue
Block a user