Module

rendering.template_functions.files

File system functions for templates.

Provides 3 functions for reading files and checking file existence.

Functions

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

Register file system functions with Jinja2 environment.

Parameters 2

Name Type Default Description
env Environment
site Site
read_file
Read file contents. Uses bengal.utils.file_io.read_text_file internally for robust file reading wi…
2 str
def read_file(path: str, root_path: Path) -> str

Read file contents.

Uses bengal.utils.file_io.read_text_file internally for robust file reading with UTF-8/latin-1 encoding fallback and comprehensive error handling.

Parameters 2

Name Type Default Description
path str

Relative path to file

root_path Path

Site root path

Returns

str

File contents as string

file_exists
Check if file exists.
2 bool
def file_exists(path: str, root_path: Path) -> bool

Check if file exists.

Parameters 2

Name Type Default Description
path str

Relative path to file

root_path Path

Site root path

Returns

bool

True if file exists

file_size
Get human-readable file size.
2 str
def file_size(path: str, root_path: Path) -> str

Get human-readable file size.

Parameters 2

Name Type Default Description
path str

Relative path to file

root_path Path

Site root path

Returns

str

File size as human-readable string (e.g., "1.5 MB")