承接 melisplatform/melis-cms-twig 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

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.

  1. Inside your site's layout view folder, create a view file with a twig file extension:

    ..\view\layout\defaultTwigLayout.twig

    This 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.

  1. Inside your site's view folder, create a new file:

    ..\view\my-demo-site-name\home\my-index.twig

    Sample child templates: index.twig or news-list.twig

  2. Inside Melis Platform, go to MelisCms > Site Tools > Template manager, and add a New 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
  1. Inside Melis Platform, go to MelisCms > Site tree view. Create a new page.

  2. Set the page's Template to your child template from the previous step. Select Draft to 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

  1. Create/Copy the helper class that extends Laminas's AbstractHelper.

  2. Implement the __invoke method that it calls your plugin: ServiceManager->get('ControllerPluginManager')->get('YourPlugin').

  3. return the result of ViewRenderer->render(YourPlugin).

II. Helper Factory creation

  1. Create/Copy the helper factory class that implements Laminas's FactoryInterface

  2. Implement the createService method 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.

  1. 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

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 melisplatform/melis-cms-twig 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: OSL-3.0
  • 更新时间: 2019-09-30