morningtrain/wp-view
Composer 安装命令:
composer require morningtrain/wp-view
包简介
Laravel views and blade for WordPress
README 文档
README
Laravel blade and view for WordPress with custom directives.
Table of Contents
Introduction
Getting Started
To get started install the package as described below in Installation.
To use the tool have a look at Usage
Installation
Install with composer
composer require morningtrain/wp-view
Dependencies
illuminate/view
morningtrain/php-loader
PHP Loader is used to load and initialize all Hooks
Usage
For an overview see the official Laravel documentation
View directory
To set the main directory for views
\Morningtrain\WP\View\View::setup(__DIR__ . "/resources/views");
Render a view
echo \Morningtrain\WP\View\View::render('person',['name' => 'John','email' => 'john@doe.com']);
Working with namespaces
You may register a namespaced for a set of views. This is especially useful when writing plugins as you may group all
your plugin views and not worry about duplicate naming. Views in a namespace may be overwritten in the main namespace as
long as you use first() instead of render().
Eg. View::first(['vendor/myPlugin/myview','myPlugin::myview]) will render from the vendor dir first if the view
exists, thereby allowing theme authors to overwrite this view when necessary.
Registering a namespace
echo \Morningtrain\WP\View\View::addNamespace('myPlugin', __DIR__ . "/resources/views");
Using a namespace
echo \Morningtrain\WP\View\View::render('myPlugin::person',['name' => 'John','email' => 'john@doe.com']);
Custom @directives
This package contains some custom blade directives that you may use:
@wpauth()
<div>
@wpauth()
Hello @username!
@else
<a>Login</a>
@endwpauth
</div>
@header()
Acts the same as : https://developer.wordpress.org/reference/functions/get_header/
The following will render the header.blade.php view or header-small.blade.php
@header() @header('small')
@footer()
Acts the same as : https://developer.wordpress.org/reference/functions/get_footer/
The following will render the footer.blade.php view or footer-dark.blade.php
@footer() @footer('dark')
@script()
An easy way to enqueue an already registered script.
Using this directive is the same as calling wp_enqueue_script() with only the handle.
@script('swiper') <section id="my-cool-slider"> ... </section>
@style()
An easy way to enqueue an already registered stylesheet.
Using this directive is the same as calling wp_enqueue_style() with only the handle.
@style('employees') <section id="employees" class="employees list"> ... </section>
@username()
Prints the username of the currently logged in user or an empty string if no one is logged in.
@cache()
Caches content in a transient and uses the cached data if it exists
<div>
<h3>Cache test for post: {!! $postId !!}</h3>
@if(!empty($postId))
@cache("post_card_{$postId}")
<aside @class(['post-card', "post-card__".get_post_type($postId)])>
<h3>{!! get_the_title($postId) !!}</h3>
<p>{{ get_the_excerpt($postId) }}</p>
<span>Yes</span>
<a href="{!! get_permalink($postId) !!}">{{__('Read more','domain')}}</a>
</aside>
@endcache
@else
<p>{{__('This is not a post','domain')}}</p>
@endif
</div>
@react()
Prints a Morningtrain ReactRenderer compatible element with optional props. This makes it easy to prepare components for react to handle in the client.
@react('myComponent', [ 'someData' => 'someValue' ])
The @react directive also supports a child view that will be rendered inside the component-wrapper until the react component is rendered. This is especially useful for skeletons and to avoid popping ins.
@react('myComponent', [ 'someData' => 'someValue' ], 'my-skeleton-view'), ['skeletonProp' => 'skeletonValue']
Credits
License
The MIT License (MIT). Please see License File for more information.
morningtrain/wp-view 适用场景与选型建议
morningtrain/wp-view 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.19k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 07 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「templating」 「wordpress」 「view」 「blade」 「morningtrain」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 morningtrain/wp-view 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 morningtrain/wp-view 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 morningtrain/wp-view 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
A Processor for Markup written in PHP. Allows extraction of Markup into a data structure, orchestrated nested manipulation of said structure, and output as (optimized) Markup.
Illuminate View for Morningmedley.
Blade template for Kirby
View5 is a version of Blade Templates for the Mvc5 Framework
E2E Studios PHP Framework adaptation of leafsphp/blade package
统计信息
- 总下载量: 2.19k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 9
- 依赖项目数: 1
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-01