hypejunction/mustache

Elgg 中的 Mustache 模板

安装: 46

依赖: 2

建议者: 0

安全: 0

星星: 0

关注者: 2

分支: 0

开放问题: 0

语言:JavaScript

类型:elgg-plugin

1.0.0 2015-10-02 08:20 UTC

This package is auto-updated.

Last update: 2024-08-29 03:56:51 UTC


README

Elgg 2.0

特性

  • 模板可以在客户端和服务器端渲染
  • 与 Elgg 的视图系统兼容
  • AMD 友好

使用方法

  1. 创建一个新的模板作为 Elgg 视图
// /my_plugin/views/default/path/to/template.html
<div class="mustache-template">
	<h3>Hello, <b>{{name}}</b></h3>
</div>

您也可以使用 PHP 视图,例如 template.html.php。这允许您调用其他视图并使用 PHP 进行操作。如果您使用这种方法,请确保在 simplecache 中注册模板视图,以便它们可以通过 AMD 访问。

// /start.php
elgg_register_simplecache_view('path/to/template.html.php');
// /my_plugin/views/default/path/to/template.html.php
<div class="mustache-template">
	<h3>Hello, <b>{{name}}</b></h3>
	<?= elgg_view('path/to/other/template.html') ?>
</div>
  1. 服务器端渲染
	echo mustache()->render(elgg_view('mustache/template.html'), array(
		'name' => elgg_get_logged_in_user_entity()->name,
	));
  1. 客户端渲染
define(function(require) {

	var elgg = require('elgg');
	var mustache = require('mustache');
	var template = require('text!mustache/template.html');

	var view = mustache.render(template, {
		name: elgg.get_logged_in_user_entity().name
	});

	$('body').html(view);

});

文档