Grantlee  5.1.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:
Inheritance graph
[legend]

Public Member Functions

bool canLoadTemplate (const QString &name) const override
 
QPair< QString, QStringgetMediaUri (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 190 of file templateloader.h.

Member Function Documentation

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.

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

Return a complete URI for media identified by fileName.

Implements Grantlee::AbstractTemplateLoader.

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.

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.