feature:hook:add

Introduction

feature:hook:add adds a template hook to an editable feature. It appends a callback stub and its register_template_hook call to hooks.py, and lists the slot in the feature’s contract.

splent feature:hook:add splent_feature_notes layout.sidebar render_notes_sidebar
✅ Hook 'layout.sidebar' → render_notes_sidebar() added to hooks.py.
✅ Contract updated in pyproject.toml.

  Implement your hook at:
  /workspace/splent_feature_notes/src/splent_io/splent_feature_notes/hooks.py

Writing the callback

The command appends this stub. A new hooks.py gets the framework imports first.

def render_notes_sidebar():
    return ""  # TODO: render your hook fragment here


register_template_hook("layout.sidebar", render_notes_sidebar)

Replace the body with a render_template(...) call or an HTML string. When the slot passes context, such as the item of a per-item slot, change the signature to def render_notes_sidebar(*args, **kwargs):.


What changes in the contract

The slot is added to [tool.splent.contract.provides].hooks. Only that key changes, and comments and layout stay. If pyproject.toml cannot be edited safely, hooks.py is left untouched too.


Reference

Arguments

Argument Description
FEATURE_REF An editable feature, splent_feature_notes or splent-io/splent_feature_notes
SLOT The hook slot, such as layout.sidebar
FUNCTION_NAME The callback’s Python name, such as render_notes_sidebar

Errors

Message What to do
Editable feature not found: <name> It looks at the workspace root, then in .splent_cache/features/<namespace>/. Create the feature, or run feature:unlock on a pinned one
feature:hook:add only works on editable features. Drop the @version suffix
Slot '<slot>' is already registered in hooks.py. Pick another slot, or remove the old one first
Function name '<name>' is already defined in hooks.py. Pick another name
'<name>' is not a valid Python function name. Use an identifier that is not a keyword
'<slot>' cannot be a slot name ... Drop quotes, backslashes and spaces
Could not update [tool.splent.contract.provides].hooks ... Edit that key by hand

Requirements

  • A selected product (SPLENT_APP).
  • An editable feature. A versioned snapshot cannot be edited.

See also


Back to top

splent. Distributed by an LGPL license v3. Contact us: drorganvidez@us.es