定制 hypejunction/elgg-twig 二次开发

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

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

hypejunction/elgg-twig

Composer 安装命令:

composer require hypejunction/elgg-twig

包简介

Twig Template Rendering for Elgg

README 文档

README

Elgg 2.3

Adds support for twig templates in Elgg

Using Templates

To add a twig template, simply add a file with .twig extension into your plugin's views, under default viewtype.

<!-- my_plugins/views/default/test.twig -->

<div class="hello">Hello, {{ name }}</div>

To render a template use ``elgg_twig()with or without a view name without.twig` extension:

$user = elgg_get_logged_in_user_entity();

echo elgg_twig('test', ['name' => $user->getDispayName()];

You can override templates like any other view, but you can not extend them or filter them using hooks.

Development

To simplify development, set environment config value to development, otherwise you need to flush caches to reload template changes.

elgg_set_config('environment', 'development');

Globals

Globals available in templates

  • app - application data
    • app.user - logged in user entity
    • app.site - site entity
    • app.registrationUrl - registration URL
    • app.loginUrl - login URL

Functions

Function available in templates

  • echo() - equivalent of elgg_echo()
  • view() - equivalent of elgg_view()
  • assetUrl() - equivalent of elgg_get_simplecache_url()
  • requireJs() - equivalent of elgg_require_js()

Notes

I have initially taught elgg_view() to render twig templates, but it had a negative performance impact, likely because of a view_vars hook registered for all views. Until there is a wildcard hook registration, elgg_twig() is the way to go, however it does not allow view vars to be filtered or views to be extended, which in the end is somewhat a win, because of simplicity.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2019-02-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固