stuartcusackie/statamic-blade-view-data 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固