feat: inject _.canister.name into recipe template context#567
Open
marc0olo wants to merge 6 commits into
Open
Conversation
raymondk
reviewed
May 26, 2026
raymondk
reviewed
May 26, 2026
Recipes can now use `{{icp.canister_name}}` to reference the canister
name from icp.yaml without repeating it in the configuration block.
The `icp` namespace is reserved and always overrides any user-supplied
value.
Affects the Rust recipe (`{{package}}`) and Motoko recipe (`{{name}}`),
which can switch to `{{icp.canister_name}}` in a follow-up.
Renames the built-in recipe variable namespace from `{{icp.canister_name}}`
to `{{_.canister.name}}` following review feedback to use a more generic,
non-brand-tied reserved prefix and a nested struct for future extensibility.
17e9e4f to
b18bee7
Compare
There was a problem hiding this comment.
Pull request overview
Adds a CLI-injected Handlebars template context value for the current canister name so recipes can reference it without duplicating configuration, and updates docs/tests accordingly.
Changes:
- Extend the recipe resolver interface to accept
canister_nameand pass it from manifest consolidation. - Inject the reserved
_namespace into the Handlebars render context (including_.canister.name) and add coverage for injection/override behavior. - Update recipe documentation and examples to use
{{_.canister.name}}, and document built-in recipe variables.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/guides/creating-recipes.md | Updates examples to use {{_.canister.name}} and adds a “Built-in Recipe Variables” section (contains a namespace wording inconsistency). |
| docs/concepts/recipes.md | Documents built-in _.* variables and reserved _ namespace. |
| crates/icp/src/project.rs | Passes canister name into recipe resolver during manifest consolidation (formatting issue in changed hunk). |
| crates/icp/src/lib.rs | Updates test mock resolver signature to match new Resolve trait. |
| crates/icp/src/canister/recipe/mod.rs | Updates Resolve trait signature to accept canister_name. |
| crates/icp/src/canister/recipe/handlebars.rs | Injects _.canister.name into Handlebars context and adds tests for injection/replace-helper/override behavior (comment/test naming inconsistencies). |
| CHANGELOG.md | Adds unreleased entry documenting {{_.canister.name}} and reserved _ namespace. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix stale comments in handlebars.rs still referencing icp.* / icp key
- Rename test functions from icp_canister_name_* / icp_namespace_* to
match the actual _ reserved namespace
- Fix {{#if optimize}} → {{#if shrink}} inconsistency in recipe docs example
Line 151 still referred to the reserved `icp` namespace; update to `_`.
_.canister.name into recipe template context
marc0olo
added a commit
to dfinity/icp-cli-templates
that referenced
this pull request
May 26, 2026
With _.canister.name now injected automatically by icp-cli (see dfinity/icp-cli#567), the `name` configuration param is no longer needed in recipe configs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
{{_.canister.name}}as a built-in recipe variable, automatically injected into every Handlebars recipe template from the canister name inicp.yaml_namespace is reserved and cannot be overridden by user-providedconfiguration:values{{ replace "-" "_" _.canister.name }}for Rust WASM artifact filenamesdocs/concepts/recipes.mdanddocs/guides/creating-recipes.mdto document built-in recipe variables and use{{_.canister.name}}throughout all examplesdocs/guides/using-recipes.mdwill be updated separately once the official recipes (@dfinity/rust,@dfinity/motoko) are updated to use{{_.canister.name}}in icp-cli-recipes