Grantlee: Grantlee::InMemoryTemplateLoader Class Reference

Grantlee 5.3.0

Public Member Functions | List of all members
Grantlee::InMemoryTemplateLoader Class Reference

The InMemoryTemplateLoader loads Templates set dynamically in memory. More...

`#include <grantlee/templateloader.h>`

Inheritance diagram for Grantlee::InMemoryTemplateLoader:
[legend]

## Public Member Functions
bool | canLoadTemplate (const QString &name) const override
QPair< QString, QString > | getMediaUri (const QString &fileName) const override
Template | loadByName (const QString &name, Engine const *engine) const override
void | setTemplate (const QString &name, const QString &content)
Public Member Functions inherited from Grantlee::AbstractTemplateLoader
virtual | ~AbstractTemplateLoader ()

## Detailed Description

This class is mostly used for testing purposes, but can also be used for simple uses of Grantlee.

Templates can be made available using the setTemplate method, and will then be retrieved by the Grantlee::Engine as appropriate.

Definition at line 195 of file templateloader.h.

## Member Function Documentation

## ◆ canLoadTemplate()

bool Grantlee::InMemoryTemplateLoader::canLoadTemplate | ( | const QString & | name | ) | const
| overridevirtual

Return true if a Template identified by `name` exists and can be loaded.

Implements Grantlee::AbstractTemplateLoader.

## ◆ getMediaUri()

QPair< QString, QString > Grantlee::InMemoryTemplateLoader::getMediaUri | ( | const QString & | fileName | ) | const
| overridevirtual

Return a complete URI for media identified by fileName.

Implements Grantlee::AbstractTemplateLoader.

## ◆ loadByName()

Template Grantlee::InMemoryTemplateLoader::loadByName | ( | const QString & | name,
|  | Engine const * | engine ) const
| overridevirtual

Load a Template called `name`. Return an invalid Template if no content by that name exists.

Implements Grantlee::AbstractTemplateLoader.

## ◆ setTemplate()

void Grantlee::InMemoryTemplateLoader::setTemplate | ( | const QString & | name,
|  | const QString & | content )

Add a template content to this Loader.

Example:

auto loader = QSharedPointer<InMemoryTemplateLoader::create();
loader->setTemplate( "name_template", "My name is {{ name }}" );
loader->setTemplate( "age_template", "My age is {{ age }}" );
engine->addTemplateLoader( loader );
// Both templates may now be retrieved by calling Engine::loadByName.
Grantlee::registerMetaType
int registerMetaType()
Registers the type RealType with the metatype system.
Definition metatype.h:182