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 ()
virtual bool | canLoadTemplate (const QString &name) const =0
virtual QPair< QString, QString > | getMediaUri (const QString &fileName) const =0
virtual Template | loadByName (const QString &name, Engine const *engine) const =0

## 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
| override virtual

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
| override virtual

Return a complete URI for media identified by fileName.

Implements Grantlee::AbstractTemplateLoader.

## ◆ loadByName()

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

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.