blockly > CodeGenerator > injectId
CodeGenerator.injectId() method
Inject a block ID into a message to replace '%1'. Used for STATEMENT_PREFIX, STATEMENT_SUFFIX, and INFINITE_LOOP_TRAP.
Signature:
injectId(msg: string, block: Block): string;
Parameters
Parameter |
Type |
Description |
msg |
string |
Code snippet with '%1'. |
block |
Block |
Block which has an ID. |
Returns:
string
Code snippet with ID.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-18 UTC.
[null,null,["Last updated 2024-09-18 UTC."],[[["The `injectId` method replaces '%1' in a code snippet with a block's ID."],["It's primarily used for statement prefixes, suffixes, and infinite loop traps."],["The method takes the code snippet and the block as input."],["It returns the modified code snippet with the block ID injected."]]],["The `injectId` method, part of the `CodeGenerator` class, replaces the '%1' placeholder within a code snippet (`msg`) with the ID of a specified `Block`. This functionality is utilized for `STATEMENT_PREFIX`, `STATEMENT_SUFFIX`, and `INFINITE_LOOP_TRAP`. It takes a string (`msg`) and a `Block` as input, then returns the modified code snippet with the block's ID inserted.\n"]]