From 30ce89238b8612987fc1d31b11ce8bf0dbb92cd2 Mon Sep 17 00:00:00 2001 From: Joseph Woo Date: Thu, 7 May 2020 16:42:27 -0700 Subject: [PATCH] Updated .Net section in sdk.md --- AdaptiveCards/templating/sdk.md | 36 ++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/AdaptiveCards/templating/sdk.md b/AdaptiveCards/templating/sdk.md index 7137a3787..93f28737c 100644 --- a/AdaptiveCards/templating/sdk.md +++ b/AdaptiveCards/templating/sdk.md @@ -91,26 +91,44 @@ Import the library using AdaptiveCards.Templating ``` -Use the templating engine by passing in your template JSON and data JSON. - ```cs var templateJson = @" { ""type"": ""AdaptiveCard"", - ""version"": ""1.0"", + ""version"": ""1.2"", ""body"": [ { ""type"": ""TextBlock"", - ""text"": ""Hello {name}"" + ""text"": ""Hello ${name}!"" } ] }"; -var dataJson = @" -{ - ""name"": ""Mickey Mouse"" +var dataJson = @"{ + ""person"": { + ""name"": ""Mickey Mouse"" + } }"; -var transformer = new AdaptiveTransformer(); -var cardJson = transformer.Transform(templateJson, dataJson); +// Create a Template instance from the template payload +AdaptiveCardTemplate template = new AdaptiveCardTemplate(jsonTemplate); + +// Create a data binding context, and set its $root property to the +// data object to bind the template to +var context = new EvaluationContext +{ + Root = dataJson +}; + + +// "Expand" the template - this generates the final Adaptive Card, +string cardJson = template.Expand(context); + +AdaptiveCardParseResult parseResult = AdaptiveCard.FromJson(cardJson); + +// ready to render +AdaptiveCard card = parseResult.Card; + +// Render the card +RenderedAdaptiveCard renderedCard = Renderer.RenderCard(card); ```