@@ -193,17 +193,27 @@ class ContextUpdater(ContextHook):
193193 └── 📄 {{module_name}}.py.jinja
194194```
195195
196- ## How does it work?
197-
198- Beware the ugly hack!
199- Upon loading the special * loader* extension,
200- the function responsible for importing
201- a Python object using its dotted-path (a string)
202- is patched in the ` jinja.environment ` module,
203- where it's used to load extensions.
204- The patched version adds support
205- for loading extensions using relative file paths.
206- The file system loader of the Jinja environment
207- and its ` searchpaths ` attribute are used to
208- find the local clone of the template and determine
209- the absolute path of the extensions to load.
196+ You can do many more things with a context hook,
197+ like downloading data from external resources
198+ to include it in the context, etc.
199+
200+ > [ !TIP]
201+ > ** Context hooks run during every Copier rendering phase.**
202+ > During project generation or project updates, Copier passes
203+ > through several rendering phases: when prompting (questions / answers),
204+ > when rendering files, when running tasks, and when running migrations.
205+ >
206+ > By default, a context hook runs during all these phases,
207+ > possibly multiple times, for example once per prompted question,
208+ > or once per rendered file. The task of running the hook only once,
209+ > or during a specific phase only, is left to you.
210+ >
211+ > To run only once, you can use caching within your class
212+ > (for example by storing computed values in class variables).
213+ >
214+ > To run during a specific phase only, you can check the value
215+ > of ` context["_copier_phase"] ` (Copier 9.5+), which is one of:
216+ > ` "prompt" ` , ` "render" ` , ` "tasks" ` , ` "migrate" ` .
217+ >
218+ > Other key-value pairs can be found in the context
219+ > that you might find useful (Copier configuration, etc.).
0 commit comments