ERB Rendering¶
ERB templates are evaluated on demand when to_s is called.
Basics¶
Any <%= expression %> in the content is evaluated as Ruby:
Template Parameters¶
Parameters declared in the YAML front-matter are available as local methods inside ERB:
parsed = PM.parse('greeting.md')
parsed.to_s #=> "Hello, World!"
parsed.to_s('name' => 'Alice') #=> "Hello, Alice!"
See Parameters for details on required vs default values.
Registered Directives¶
Custom directives registered with PM.register are also available in ERB:
See Custom Directives for the full guide.
Built-in Directives¶
PM includes one built-in directive:
include-- Include and render another prompt file. See Including Files.
Disabling ERB¶
Set erb: false in the file's YAML metadata:
When ERB is disabled:
to_sreturns the content without template evaluation- Parameters are ignored
- The
includedirective does not execute metadata.includesis an empty array afterto_s
Global Default¶
Per-file metadata always overrides the global setting. A file with erb: true gets ERB rendering even when the global default is false.
Pipeline Position¶
ERB rendering is the last stage of the pipeline, executed on demand:
- Strip HTML comments
- Extract YAML metadata
- Shell expansion (at parse time)
- ERB rendering (at
to_stime)
This means shell variables are already expanded before ERB sees the content. If content contains both $VAR and <%= param %>, the shell variable is resolved first, then ERB fills in the parameters.