Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

(no description)

File Size: 123 lines (4 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Mustache_Loader_InlineLoader:: (3 methods):
  __construct()
  load()
  loadTemplates()


Class: Mustache_Loader_InlineLoader  - X-Ref

A Mustache Template loader for inline templates.

With the InlineLoader, templates can be defined at the end of any PHP source
file:

$loader  = new Mustache_Loader_InlineLoader(__FILE__, __COMPILER_HALT_OFFSET__);
$hello   = $loader->load('hello');
$goodbye = $loader->load('goodbye');

__halt_compiler();

@@ hello
Hello, {{ planet }}!

@@ goodbye
Goodbye, cruel {{ planet }}

Templates are deliniated by lines containing only `@@ name`.

The InlineLoader is well-suited to micro-frameworks such as Silex:

$app->register(new MustacheServiceProvider, array(
'mustache.loader' => new Mustache_Loader_InlineLoader(__FILE__, __COMPILER_HALT_OFFSET__)
));

$app->get('/{name}', function ($name) use ($app) {
return $app['mustache']->render('hello', compact('name'));
})
->value('name', 'world');

// ...

__halt_compiler();

@@ hello
Hello, {{ name }}!
__construct($fileName, $offset)   X-Ref
The InlineLoader requires a filename and offset to process templates.

The magic constants `__FILE__` and `__COMPILER_HALT_OFFSET__` are usually
perfectly suited to the job:

$loader = new Mustache_Loader_InlineLoader(__FILE__, __COMPILER_HALT_OFFSET__);

Note that this only works if the loader is instantiated inside the same
file as the inline templates. If the templates are located in another
file, it would be necessary to manually specify the filename and offset.

param: string $fileName The file to parse for inline templates
param: int    $offset   A string offset for the start of the templates.

load($name)   X-Ref
Load a Template by name.

param: string $name
return: string Mustache Template source

loadTemplates()   X-Ref
Parse and load templates from the end of a source file.