Grantlee: Grantlee::Variable Class Reference

Grantlee 5.3.0

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

A container for static variables defined in Templates. More...

`#include <grantlee/variable.h>`

## Public Member Functions
| Variable ()
| Variable (const QString &var)
| Variable (const Variable &other)
| ~Variable ()
bool | isConstant () const
bool | isLocalized () const
bool | isTrue (Context *c) const
bool | isValid () const
QVariant | literal () const
QStringList | lookups () const
Variable & | operator= (const Variable &other)
QVariant | resolve (Context *c) const

## Detailed Description

This class is only relevant to Template tag authors.

When processing a template tag in a AbstractNodeFactory implementation, it will sometimes make sense to process arguments to the tag as Grantlee::Variables. Note that usually they should be processed as FilterExpression objects instead.

Arguments to the tag can be used to construct Variables, which may then be resolved into the objects they represent in the given Context in the render stage.

Author
  Stephen Kelly steve.nosp@m.ire@.nosp@m.gmail.nosp@m..com

Definition at line 52 of file variable.h.

## Constructor & Destructor Documentation

## ◆ Variable() [1/3]

Grantlee::Variable::Variable | ( |  | ) |

Constructs an invalid Variable

## ◆ Variable() [2/3]

Grantlee::Variable::Variable | ( | const QString & | var | ) |
| explicit

Creates a Variable represented by the given `var`

## ◆ Variable() [3/3]

Grantlee::Variable::Variable | ( | const Variable & | other | ) |

Copy constructor

## ◆ ~Variable()

Grantlee::Variable::~Variable | ( |  | ) |

Destructor

## Member Function Documentation

## ◆ isConstant()

bool Grantlee::Variable::isConstant | ( |  | ) | const

Returns whether this Variable is a constant in the Template. A constant is represented as a static string in the template

Text content
{% some_tag "constant" variable %}

## ◆ isLocalized()

bool Grantlee::Variable::isLocalized | ( |  | ) | const

Returns whether this variable is localized, that is, if it is wrapped with _().

See also
  Internationalization and Localization

## ◆ isTrue()

bool Grantlee::Variable::isTrue | ( | Context * | c | ) | const

Returns whether this Variable evaluates to true with the Context `c`.

## ◆ isValid()

bool Grantlee::Variable::isValid | ( |  | ) | const

Returns whether this Variable is valid.

## ◆ literal()

QVariant Grantlee::Variable::literal | ( |  | ) | const

Returns whether this variable is a literal string or number. A literal Variable does not have any lookup components.

## ◆ lookups()

QStringList Grantlee::Variable::lookups | ( |  | ) | const

Returns the lookup components of this Variable.

## ◆ operator=()

Variable & Grantlee::Variable::operator= | ( | const Variable & | other | ) |

Assignment operator.

## ◆ resolve()

QVariant Grantlee::Variable::resolve | ( | Context * | c | ) | const

Resolves this Variable with the Context `c`.