Module

rendering.template_functions.data

Data manipulation functions for templates.

Provides 8 functions for working with JSON, YAML, and nested data structures.

Functions

register
Register data manipulation functions with Jinja2 environment.
2 None
def register(env: Environment, site: Site) -> None

Register data manipulation functions with Jinja2 environment.

Parameters 2

Name Type Default Description
env Environment
site Site
get_data
Load data from JSON or YAML file. Uses bengal.utils.file_io.load_data_file internally for robust f…
2 Any
def get_data(path: str, root_path: Any) -> Any

Load data from JSON or YAML file.

Uses bengal.utils.file_io.load_data_file internally for robust file loading with error handling and logging.

Parameters 2

Name Type Default Description
path str

Relative path to data file

root_path Any

Site root path

Returns

Any

Parsed data (dict, list, or primitive)

jsonify
Convert data to JSON string.
2 str
def jsonify(data: Any, indent: int | None = None) -> str

Convert data to JSON string.

Parameters 2

Name Type Default Description
data Any

Data to convert (dict, list, etc.)

indent int | None None

Indentation level (default: None for compact)

Returns

str

JSON string

merge
Merge two dictionaries. Delegates to bengal.config.merge.deep_merge for consistent behavior across…
3 dict[str, Any]
def merge(dict1: dict[str, Any], dict2: dict[str, Any], deep: bool = True) -> dict[str, Any]

Merge two dictionaries.

Delegates to bengal.config.merge.deep_merge for consistent behavior across the codebase.

Parameters 3

Name Type Default Description
dict1 dict[str, Any]

First dictionary

dict2 dict[str, Any]

Second dictionary (takes precedence)

deep bool True

Perform deep merge (default: True)

Returns

dict[str, Any]

Merged dictionary

has_key
Check if dictionary has a key.
2 bool
def has_key(data: dict[str, Any], key: str) -> bool

Check if dictionary has a key.

Parameters 2

Name Type Default Description
data dict[str, Any]

Dictionary to check

key str

Key to look for

Returns

bool

True if key exists

get_nested
Access nested data using dot notation.
3 Any
def get_nested(data: dict[str, Any], path: str, default: Any = None) -> Any

Access nested data using dot notation.

Parameters 3

Name Type Default Description
data dict[str, Any]

Dictionary with nested data

path str

Dot-separated path (e.g., "user.profile.name")

default Any None

Default value if path not found

Returns

Any

Value at path or default

keys_filter
Get dictionary keys as list.
1 list[str]
def keys_filter(data: dict[str, Any]) -> list[str]

Get dictionary keys as list.

Parameters 1

Name Type Default Description
data dict[str, Any]

Dictionary or DotDict

Returns

list[str]

List of keys

values_filter
Get dictionary values as list.
1 list[Any]
def values_filter(data: dict[str, Any]) -> list[Any]

Get dictionary values as list.

Parameters 1

Name Type Default Description
data dict[str, Any]

Dictionary or DotDict

Returns

list[Any]

List of values

items_filter
Get dictionary items as list of (key, value) tuples.
1 list[tuple[str, Any]]
def items_filter(data: dict[str, Any]) -> list[tuple[str, Any]]

Get dictionary items as list of (key, value) tuples.

Parameters 1

Name Type Default Description
data dict[str, Any]

Dictionary or DotDict

Returns

list[tuple[str, Any]]

List of (key, value) tuples