basteyy/plates-url-toolset
Composer 安装命令:
composer require basteyy/plates-url-toolset
包简介
A few functions for url handling in plates
README 文档
README
This plugin provides a few URL functions for use within Plates templates.
Setup
First, download the library via Composer:
composer require basteyy/plates-url-toolset
Of course, you can download the library manually and include it in your project. But I recommend using Composer.
Usage
Load Extension
To make the URL tools available, load the extension into your Plates scope:
/** @var \League\Plates\Engine $engine */ $engine->loadExtension(new \basteyy\PlatesUrlToolset\PlatesUrlToolset());
Load Options
Customize the extension by setting options when loading it:
/** @var \League\Plates\Engine $engine */ $engine->loadExtension( new \basteyy\PlatesUrlToolset\PlatesUrlToolset( null, // The base URL for all URLs. Should be something like https://example.org true, // Change the default value for using absolute URLs [] // Register named URLs for later use ));
Usages Inside the Templates
For all the examples below, I use example.org as the hypothetical website URL.
Get the Current URL
echo $this->getCurrentUrl(); // Displays the current URL
Result:
http://example.org/foobar
Create an HTML Link
echo $this->getLink('/foo', 'Click it!!', 'Yes, click me', 'btn big', false);
Result:
<a href="/foo" title="Yes, click me" class="btn big">Click it!!</a>
Get a Named URL
// Register the link in the constructor or via $this->addNamedUrl('linkname', 'foobar'); echo $this->getNamedUrl('linkname'); echo $this->getNamedUrl('linkname', true);
Result:
/foobar https://example.org/foobar
Get a Named HTML Link
// Register the link in the constructor or via $this->addNamedUrl('linkname', 'foobar-123456789'); echo $this->getNamedLink('linkname', 'Click it!!', 'Yes, click me', 'btn big', false);
Result:
<a href="/foobar-123456789" title="Yes, click me" class="btn big">Click it!!</a>
Get a URL with a Debugging Timestamp Appended
// Register the link in the constructor or via echo $this->getDebugUrl('/foobar/file/something.css'); echo $this->getDebugUrl('/foobar/file/bar.jpg', true, 'blabla', 'aaaa');
Result:
/foobar/file/something.css?request_time=1234567 (current timestamp) https://example.org/foobar/file/bar.jpg?blabla=aaaa
License
The MIT License (MIT). Please see License File for more information.
Contributing
Feel free to contribute to this project. Just create a pull request with your changes.
Support
统计信息
- 总下载量: 85
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-04-14