templater
¶
templates_directory = pathlib.Path(__file__).parent / 'templates'
module-attribute
¶
get_jinja2_environment(input_file_path=None)
cached
¶
Create cached Jinja2 environment with custom filters and template loaders.
Why
Template rendering is called multiple times per render. Caching environment prevents repeated filesystem scans. Loader hierarchy enables user template overrides by checking input file directory before built-in templates.
Parameters:
-
input_file_path(Path | None, default:None) –Path to input file for user template override resolution.
Returns:
-
Environment–Configured Jinja2 environment with filters and loaders.
Source code in src/rendercv/renderer/templater/templater.py
render_full_template(rendercv_model, file_type)
¶
Render complete CV document by assembling preamble, header, and sections.
Why
CV generation requires consistent structure across formats. This orchestrates model processing, template rendering for each component, and assembly into final document following proper order.
Example
Parameters:
-
rendercv_model(RenderCVModel) –CV model to render.
-
file_type(Literal['typst', 'markdown']) –Output format for template selection and processing.
Returns:
-
str–Complete rendered document as string.
Source code in src/rendercv/renderer/templater/templater.py
render_html(rendercv_model, markdown)
¶
Convert Markdown to HTML and wrap with full HTML template.
Why
HTML output requires both content conversion (Markdown to HTML body) and document structure (head, CSS, metadata). Separate function handles HTML- specific workflow distinct from Typst/Markdown direct generation.
Example
Parameters:
-
rendercv_model(RenderCVModel) –CV model for template context.
-
markdown(str) –Markdown content to convert.
Returns:
-
str–Complete HTML document.
Source code in src/rendercv/renderer/templater/templater.py
render_single_template(file_type, relative_template_path, rendercv_model, **kwargs)
¶
Render single Jinja2 template with user override support. Arbitrary keyword arguments may be passed to the template as additional template variables.
Why
Users can override built-in templates by placing custom templates in theme folder alongside input file. Typst templates check theme-specific location first, falling back to built-in templates if not found.
Example
header = render_single_template("typst", "Header.j2.typ", rendercv_model)
# First checks for classic/Header.j2.typ in input file directory
# Falls back to built-in typst/Header.j2.typ if not found
section = render_single_template(
"typst",
"SectionBeginning.j2.typ",
rendercv_model,
section_title="Experience",
)
Parameters:
-
file_type(Literal['markdown', 'typst', 'html']) –Format for template directory selection.
-
relative_template_path(str) –Template file path relative to format directory.
-
rendercv_model(RenderCVModel) –CV model providing template context.
Returns:
-
str–Rendered template as string.