hypejunction / mustache
Mustache templating in Elgg
Installs: 46
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Language:JavaScript
Type:elgg-plugin
Requires
- bower-asset/mustache.js: ~2.1.3
- mustache/mustache: ~2.9.0
Requires (Dev)
- composer/installers: 1.*
This package is auto-updated.
Last update: 2024-10-29 04:25:30 UTC
README
Features
- Templates can be rendered both client and server side
- Compatible with Elgg's view system
- AMD-friendly
Usage
- Create a new template as an Elgg view
// /my_plugin/views/default/path/to/template.html <div class="mustache-template"> <h3>Hello, <b>{{name}}</b></h3> </div>
You can also use PHP views, e.g. template.html.php
. This allows you
to call other views and do stuff with PHP. If you use this approach, be
sure to register the template views in simplecache, so that they are
accessible with 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>
- Render server-side
echo mustache()->render(elgg_view('mustache/template.html'), array( 'name' => elgg_get_logged_in_user_entity()->name, ));
- Render client-side
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); });
Docs
- mustache.js https://github.com/janl/mustache.js
- PHP Mustache https://github.com/bobthecow/mustache.php