[Templating Feature] Allow an array of AdaptiveCards as template
Related Issue
Fixes #7779
Description
The JS templating library can now accept an array of AdaptiveCards as the template.
Changes in templating
After expanding the template, we check if the remaining object is an array. If the object is an array of length 1, we return the AdaptiveCard. If the array is of length 0 or greater than 1, we log an error and return undefined.
Changes in Designer
If the given card payload is an array of AdpativeCards, we disable design mode and only show the rendered card in preview mode. This is because templating is only applied in preview mode.
Sample Card
[
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.5",
"$when": "${test}",
"body": [
{
"type": "TextBlock",
"text": "To be displayed if test === true",
"wrap": true
}
]
},
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.5",
"$when": "${!test}",
"body": [
{
"type": "TextBlock",
"text": "To be displayed if test === false",
"wrap": true
}
]
}
]
Data
{
"test": false
}
How Verified
- Added three templating unit-test (simple TextBlock, Container vs. Carousel, failure to test template error).
- Verified manually in the designer.
- Verified the new UI adjusts to high contrast.
Future work
Templating expansion warnings/errors need to be displayed in the designer (#7442)
Hi @anna-dingler. This pull request has had no recent activity for the past 5 days . Please take the necessary actions (review, address feedback or commit if reviewed already) to move this along.
I'm not understanding this. The templating engine has always accepted an array of anything (not just cards, the template engine is 100% generic and independent from AC aside from its package name) as a template.
I'm not understanding this. The templating engine has always accepted an array of anything (not just cards, the template engine is 100% generic and independent from AC aside from its package name) as a template.
@dclaux I misnamed this PR. The changes are focused on ensuring that the templating library always outputs an object (ideally an AdaptiveCard, but templating is independent as you noted above).
We haven't decided if we want to take this change in general, but we're keeping it here for now.
The templating engine should not return an object if it is fed with a template that has a top level array. It should produce an array. It should be the responsibility of the consuming application to extract what it needs to extract from the produced array. Alternatively, the consuming application could extract objects from the array and feed each one to the templating engine independently.
Also re: "if the given card payload is an array" - that is simply not possible: an Adaptive Card cannot be expressed as an array. It must be expressed as an object. An array would never pass validation against the AC schema.
Closing since we are not adding this feature right now.
Staleness reset by anna-dingler