stuartcusackie/statamic-blade-view-data
最新稳定版本:1.1.14
Composer 安装命令:
composer require stuartcusackie/statamic-blade-view-data
包简介
Access Statamic variables from any blade view or component.
README 文档
README
Facades to access Statamic data from within Blade components. This package extracts the Statamic data that is passed to your selected template and adds it to a singleton that can be accessed anywhere in your application.
DO NOT USE
Since writing this package the devs at Statamic have found a better way to access Statamic data. Use the Cascade facade in any controller or blade component:
use Facades\Statamic\View\Cascade;
$cascade = Cascade::instance()->toArray();
$page = $cascade['page'];
$globalAnalytics = $cascade['analytics'];
Installation
composer require stuartcusackie/statamic-blade-view-data
Usage
A Laravel facade is provided by the package. It has a few methods:
- StatData::context() - Returns all of the view data
- StatData::page() - Returns the Statamic page object
- StatData::site() - Returns Statamic site object
- StatData::globalSet('social') - Returns a specific global set
To use it in blade views:
StatData::globalSet('social')['facebook_url']
To use it in classes we need a forward slash:
$page = \StatData::page();
Custom Routes
Custom routes that are set up in web.php and that use custom controllers won't be initialised with the Statamic data.
If you are returning a view in your custom controllers then you can initialise the blade data like so:
View::composer('pages/custom-view', function ($view) {
\StatData::init($viewData);
});
return (new \Statamic\View\View)
->template('pages/custom-view')
->layout('layouts/app')
->with(['page' => $page]);
统计信息
- 总下载量: 105
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-07