Module

rendering.template_functions.files

File system functions for templates.

Provides 3 functions for reading files and checking file existence.

Functions

register 2 None
Register functions with template environment.
def register(env: TemplateEnvironment, site: SiteLike) -> None
Parameters
Name Type Description
env TemplateEnvironment
site SiteLike
read_file 2 str
Read file contents. Uses bengal.utils.file_io.read_text_file internally for ro…
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
Name Type Description
path str

Relative path to file

root_path Path

Site root path

Returns
str
file_exists 2 bool
Check if file exists.
def file_exists(path: str, root_path: Path) -> bool
Parameters
Name Type Description
path str

Relative path to file

root_path Path

Site root path

Returns
bool
file_size 2 str
Get human-readable file size.
def file_size(path: str, root_path: Path) -> str
Parameters
Name Type Description
path str

Relative path to file

root_path Path

Site root path

Returns
str