定制 sygytyr/yii2-mustache 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

sygytyr/yii2-mustache

Composer 安装命令:

composer require sygytyr/yii2-mustache

包简介

Mustache templating for the Yii Framework.

README 文档

README

Runtime Release License Downloads Coverage Build

Mustache templating for Yii, high-performance PHP framework.

This package provides a view renderer, the yii\mustache\ViewRenderer class. This renderer allows to use Mustache syntax in view templates.

Requirements

The latest PHP and Composer versions. If you plan to play with the sources, you will also need the latest Phing version.

Installing via Composer

From a command prompt, run:

$ composer global require fxp/composer-asset-plugin
$ composer require sygytyr/yii2-mustache

Configuring application

In order to start using Mustache you need to configure the view application component, like the following:

use yii\mustache\{ViewRenderer};
use yii\web\{View};

return [
  'components' => [
    'view' => [
      'class' => View::class,
      'renderers' => [
        'mustache' => ViewRenderer::class
      ]
    ]
  ]
];

After it's done you can create templates in files that have the .mustache extension (or use another file extension but configure the component accordingly). Unlike standard view files, when using Mustache you must include the extension in your $this->render() controller call:

return $this->render('template.mustache', [ 'model' => 'The view model' ]);

Template Syntax

The best resource to learn Mustache basics is its official documentation you can find at mustache.github.io. Additionally there are Yii-specific syntax extensions described below.

Variables

Within Mustache templates the following variables are always defined:

  • app: the Yii::$app instance.
  • this: the current View object.
  • yii.debug: the YII_DEBUG constant.
  • yii.devEnv: the YII_ENV_DEV constant.
  • yii.prodEnv: the YII_ENV_PROD constant.
  • yii.testEnv: the YII_ENV_TEST constant.

Lambdas

  • format: provides a set of commonly used data formatting methods.
  • html: provides a set of methods for generating commonly used HTML tags.
  • i18n: provides features related with internationalization (I18N) and localization (L10N).
  • url: provides a set of methods for managing URLs.

Partials

There are two ways of referencing partials:

{{> post }}
{{> @app/views/layouts/2columns }}

In the first case the view will be searched relatively to the current view path. For post.mustache that means these will be searched in the same directory as the currently rendered template.

In the second case we're using path aliases. All the Yii aliases such as @app are available by default.

See also

License

Mustache for Yii is distributed under the MIT License.

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-13