Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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.