Share via


VarBlock Class

Create a variable block.

A variable block is used to add a variable to a template. It gets rendered from KernelArguments, if the variable is not found a warning is logged and an empty string is returned. The variable must start with $ and be followed by a valid variable name. A valid variable name is a string of letters, numbers and underscores.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Constructor

VarBlock(*, content: str, name: str = '')

Parameters

Name Description
str
Required
<xref:<xref:name ->>

The content of the variable block, the name of the variable.

str
Required

The name of the variable.

Keyword-Only Parameters

Name Description
content
Required
name
Required

Examples

$var $test_var

Methods

parse_content

Parse the content and extract the name.

The parsing is based on a regex that returns the name. if the 'name' is already present then the parsing is skipped.

render

Render the variable block with the given arguments.

If the variable is not found in the arguments, return an empty string.

parse_content

Parse the content and extract the name.

The parsing is based on a regex that returns the name. if the 'name' is already present then the parsing is skipped.

parse_content(fields: Any) -> Any

Parameters

Name Description
fields
Required

render

Render the variable block with the given arguments.

If the variable is not found in the arguments, return an empty string.

render(_: Kernel, arguments: KernelArguments | None = None) -> str

Parameters

Name Description
_
Required
arguments
Default value: None

Attributes

name

name: str

type

type: ClassVar[BlockTypes] = 4