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.
This change adds support for resolving key names in objects using variables. For example, if the data passed to
carbone.render
contains:Then, in the template, we can use a key from
item.names
that depends on the passedlanguage
by using a Carbone variable (also called "alias" in the Designer documentation) with a new de-referencing syntax:Under the hood, this key reference translated to an IIFE that evaluates
_root.d.language
or returns an empty string on error (like when some object along the path is null/undefined).Only references to known variables are replaced with dynamically-computed keys, so this change preserves compatibility for users of key names with
$$
in them (they work as usual) - unless you define a variable of the same name.Square brackets were considered to give developers more familiarity (would have been similar to
obj[variable]
in JS), but ultimately a "$$" syntax was chosen that requires minimal changes to the parser/renderer logic.Note that this function only supports plain, parameter-less aliases/variables so far (no array filters), and the variable code (the part after
=
) must be eval-able.Basic tests for this renderer feature are provided.