Skip to content

Hooks Authors

Leonard Ramminger edited this page Aug 22, 2026 · 1 revision

Hooks (Authors)

Writing Lua hooks in templates.

Files

File Phase
hooks/pre.lua Before directory/file creation
hooks/before_render.lua After directories, before Prebyte
hooks/after_render.lua After Prebyte
hooks/post.lua At the end

Minimal example

hooks/before_render.lua:

write_file("before-render.txt", "before-render\n")

Available API

Function Description
write_file(path, content) Write file in build root
read_file(path) Read (build root or template root)
mkdir(path) Create directory
remove(path) Delete
exists(path) Path exists?
copy(src, dst) Copy
list_files(dir) Filenames in directory
list_dirs(dir) Subdirectories
process_string(template, values?) Prebyte on string
process_file(src, dst, values?) Render Prebyte file
exec(command) Shell command (with timeout)
get_template_root() Absolute template path
get_build_root() Absolute target path
script(name) Run script from scripts/

Also: slugify() and metadata helpers as in questions.lua.

Scripts catalog

scripts/*.lua can be invoked from hooks via script("name"). Reference: advanced_hooks_layout/scripts/create_marker.lua.

Sandbox

  • Write only inside the build root
  • Read: build root + template files
  • Path traversal (../) is rejected
  • exec is subject to hook timeout

Details: Security

Includes & hooks

pre/post can collide across includes - controlled via merge.pre_hook_conflict / merge.post_hook_conflict. before_render / after_render come from the top template.

Testing

Fixture with expected hook artifacts: tests/test_templates/advanced_hooks_layout/tests/hooks_and_lock/

tempify test advanced_hooks_layout

See also

Hooks (Users) · Template Tests

Clone this wiki locally