Skip to content
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

Updated .Net section in sdk.md #275

Merged
merged 1 commit into from
May 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions AdaptiveCards/templating/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```