-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic blocks #142
Comments
I think dedicated Not using dedicated block for this would move all content blocks to the lower level on content tree. There is no way to use this dynamic feature to create blocks on the top level of the document or on the same level where it is used. |
@dobarx I almost wrote the whole issue about The problem with a dedicated If we take a step back,
It might need a dedicated unpacking step, indeed, where all these "dynamic" blocks are unpacked into "normal" blocks. We don't need to retain the knowledge that some nodes were originally dynamic—we can adjust the template tree and continue. |
But doesn't allowing |
they are dynamic in a sense that they will be copied as part of the in the description above, Potentially, we can allow |
I've updated the issue description with the new design |
bouncing to 0.5 |
me and @Andrew-Morozko agreed to postpone dynamic feature for the document blocks |
Background
The content structure in FCL templates is static at the moment. Fabric supports content filtering during rendering (#99), but users can't mutate the document structure based on data.
Requirements
content
andsection
blocks from the context dataDesign
We introduce
dynamic
block type. It is similar to Terraform's dynamic blocks but has a different syntax.dynamic
block works with specific block types, similar toconfig
block:dynamic
block can be applied todocument
,section
andcontent
blocks.For example,
dynamic
document would look like this:Note
Dynamic blocks clone the blocks they wrap. For example
dynamic document
block isdocument
block with additional attributes, sodata
blocks can be defined. No nested blocks (apart frommeta
) can be defined in the 'dynamic content' block.dynamic
block attributes:dynamic_items_var
-- a syntactic sugar that extends thevars
block withdynamic_items
variable. The variable's value will be used as a collection to iterate over while cloning.dynamic_condition_var
-- a syntactic sugar that extends thevars
block withdynamic_condition
variable. The variable's value will be used to evaluate if thedynamic
block should produce 0 or more than 0 results.For example, this snippet shows how we can choose which block to render based on available data:
Behaviour
Execution flow
data
blocks andvars
block are executed and set in the contextvars
block is NOT executeddynamic_condition_var
is defined, it is executed.false
ornull
, the dynamic block is skipped completelytrue
or a non-null object, the execution continuesdynamic_items_var
is defined, it is executed, and the blocks is created for every element of the collection in.vars.dynamic_items
vars
block is evaluatedContext for produced blocks
Dynamic block extends the context available for produced blocks with these variables:
.vars.dynamic_item
-- the current element of the collection.vars.dynamic_item_index
-- the index of the current element of the collectionIf the dynamic block has another dynamic block nested inside (if
section
is wrapped in dynamic block),.vars.dynamic_*
variables are overwritten by the values for the inner block.Naming
If the dynamic block is named, the names of produced blocks are suffixed with the
.vars.dynamic_item_index
value, for example,section.foo[<.vars.dynamic_item_index value>]
as insection.foo[1]
If the block is unnamed, it's given a random name, and the names of the copies are suffixed too: for example,
section.24a086f[<.vars.dynamic_item_index value>]
as insection.24a086f[0]
Example
Dynamic section and dynamic content block:
renders into
The
ref
blocks should still be supported:and #29 is supported as well.
Dynamic documents
The behavior of the dynamic
document
blocks differs slightly from the behavior of other dynamic blocks.renders into 2 separate documents:
and
CLI issues
render
CLI command should supportdynamic.document.<document-name>
as a targetdata
CLI command should supportdynamic.document.<document-name>.data.<...>
as a targetThe behavior of publish / output flags in CLI should be adjusted in
dynamic
blocks as the target introduces ambiguity.References
publish
blocks and data sinks #126The text was updated successfully, but these errors were encountered: