melisplatform/melis-cms-twig
Composer 安装命令:
composer require melisplatform/melis-cms-twig
包简介
Twig as an alternative templating engine in Melis CMS pages
README 文档
README
Extends Twig's functionalities to offer an alternative rendering strategy. This module is based on ZendFramework's ZfcTwig.
Getting started
These instructions will get you a copy of the project up and running on your machine.
Installation
Run the composer command:
composer require melisplatform/melis-cms-twig
Guides
Basic usage inside Melis Platform
By default, Melis CMS Twig can be used to render a page inside Melis CMS by performing the following:
I. Base Template creation
This base template will be extended by a child layout.
-
Inside your site's layout view folder, create a view file with a
twigfile extension:..\view\layout\defaultTwigLayout.twigThis template must be registered in your site module's configuration:
// inside module.config.php return [ 'view_manager' => [ 'template_map' => [ 'MyDemoSiteName/defaultTwigLayout' => __DIR__ . '/../view/layout/defaultLayout.twig', ] ] ];
Possible contents of a base template can be seen in this sample: defaultTwigLayout.twig
II. Child Template creation
For this example, we will be creating a "Home" page.
-
Inside your site's view folder, create a new file:
..\view\my-demo-site-name\home\my-index.twigSample child templates: index.twig or news-list.twig
-
Inside Melis Platform, go to
MelisCms>Site Tools>Template manager, and add aNew template.- Site: My Demo Site Name
- Template type:
Twig - Layout:
defaultTwigLayout - Controller: Home
- Action:
myIndex
Layout shall be the base template's name as registered in your module configuration. In other words,
MyDemoSiteName/defaultTwigLayout.Action shall be the child template's comma-separated filename, transformed into Camel Case.
Inside Home Controller, implement a method named
myIndexAction(...).
III. Twig a page
-
Inside Melis Platform, go to
MelisCms>Site tree view. Create a new page. -
Set the page's
Templateto your child template from the previous step. SelectDraftto save & reload the Page.Note: To enable Twig rendering in front, enable Melis CMS Twig in in your site's
module.load.php.return [ ... 'MelisCmsTwig', ... ];
Using View Helpers
Inside your twig templates, Melis CMS Twig provides access to various View Helpers:
-
Laminas View Helpers (Layout, Doctype, etc.)
{# Generating Styles & JS in the <head> #} {{ headLink() }} {{ headScript() }} {# Using a layout variable #} {{ layout().myVar }}
-
Melis Helpers (MelisTag, MelisDragDropZone, etc.)
{# Displaying an editable text area (editable in back office only) #} {{ MelisTag(myPageId, "my-footer-title", "textarea", "My Cool Default Title") }} {# Setting a form's action via MelisLink, with configuration from Melis' SiteConfig helper #} ... <form action="{{ MelisLink(SiteConfig('search_result_page_id'), false) }}" method="get"> ...
-
Melis Plugins (MelisCmsNewsListPlugin, MelisCmsNewsLatestPlugin, & more)
{# Displaying a news list from MelisCmsNews, with parameters passed from controller #} {{ MelisCmsNewsListPlugin(listNewsParameters) }}
Converting a Melis Plugin
To make use of Melis Plugins inside Twig templates, convert them as view helpers.
I. Helper creation
-
Create/Copy the helper class that extends Laminas's
AbstractHelper. -
Implement the
__invokemethod that it calls your plugin:ServiceManager->get('ControllerPluginManager')->get('YourPlugin'). -
returnthe result ofViewRenderer->render(YourPlugin).
II. Helper Factory creation
-
Create/Copy the helper factory class that implements Laminas's
FactoryInterface -
Implement the
createServicemethod that it instantiates the Helper from the previous step, passing all the needed parameters.return new YourPluginHelper($serviceManager, $var1, $var2);
III. Helper Registration
The conversion process actually creates a Twig function injected inside Melis CMS Twig's Environment via ZF2's View Helper Manager.
This is the reason why you need to register your plugin under the view_helpers key.
-
Under your site's configuration (
my-demo-site-name\config\module.config.php), register your plugin's helper:... 'view_helpers' => [ 'factories' => [ 'YourPlugin' => 'MelisYourModule\View\Helper\Factory\YourPluginHelperFactory', ], ], 'view_manager' => [...], ...
References
These documentations mainly helped in understanding & implementing the module:
Authors
- Melis Technology - www.melistechnology.com
See also the list of contributors who participated in this project.
License
This project is licensed under the Melis Technology premium versions end user license agreement (EULA) - see the LICENSE.md file for details
melisplatform/melis-cms-twig 适用场景与选型建议
melisplatform/melis-cms-twig 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 840 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 09 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「twig」 「zf2」 「module」 「cms」 「melis」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 melisplatform/melis-cms-twig 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 melisplatform/melis-cms-twig 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 melisplatform/melis-cms-twig 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
LosLog provides some log utility
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
EdpModuleLayouts is very simple Laminas module for making module-specific layouts insanely easy.
统计信息
- 总下载量: 840
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: OSL-3.0
- 更新时间: 2019-09-30