Module

rendering.template_functions.data

Data manipulation functions for templates.

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

Functions

register 2 None
Register functions with template environment.
def register(env: TemplateEnvironment, site: SiteLike) -> None
Parameters
Name Type Description
env TemplateEnvironment
site SiteLike
get_data 2 Any
Load data from JSON or YAML file. Uses bengal.utils.file_io.load_data_file int…
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
Name Type Description
path str

Relative path to data file

root_path Any

Site root path

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

Data to convert (dict, list, etc.)

indent int | None

Indentation level (default: None for compact)

Default:None
Returns
str
merge 3 dict[str, Any]
Merge two dictionaries. Delegates to bengal.config.merge.deep_merge for consis…
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
Name Type Description
dict1 dict[str, Any]

First dictionary

dict2 dict[str, Any]

Second dictionary (takes precedence)

deep bool

Perform deep merge (default: True)

Default:True
Returns
dict[str, Any]
has_key 2 bool
Check if dictionary has a key.
def has_key(data: dict[str, Any], key: str) -> bool
Parameters
Name Type Description
data dict[str, Any]

Dictionary to check

key str

Key to look for

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

Dictionary with nested data

path str

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

default Any

Default value if path not found

Default:None
Returns
Any
keys_filter 1 list[str]
Get dictionary keys as list.
def keys_filter(data: dict[str, Any]) -> list[str]
Parameters
Name Type Description
data dict[str, Any]

Dictionary or DotDict

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

Dictionary or DotDict

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

Dictionary or DotDict

Returns
list[tuple[str, Any]]