Dynamic Content Generation
By embedding C# scripts and using Next Design's API to dynamically generate content, you can freely express model information, aggregation results, and more.
Overview
- By embedding C# scripts in the view definition of the Markdown editor, you can format model information in Markdown format for models with the same view, or collect information from related models and display aggregation results.
- By writing C# scripts for each model, you can dynamically generate content specific to that model without changing the profile.
Using Scripts in View Definitions
To embed a script in the view definition of the Markdown editor and generate and display dynamic content from models with the same view, follow these steps:
Instructions
- Switch to the Markdown Editor view for the target model.
- Open the Inspector and switch to the Markdown Editor tab.
- Configure the Markdown Editor tab as follows:
- Specify the field where you want to write the script in the Fields setting.
- Select Run View Definition Script in the Execution Mode setting.
- Click the View Definition Script button and write the script in the Edit Script dialog box.
- Click OK in the Edit Script dialog box to close the dialog box. The Markdown generated by the script will be displayed in the Markdown Editor view.
Note
- If you select "Execute View Definition Scripts" in the "Execution Mode" settings, you will be unable to change the "Files" setting.
- If you want to change the "Files" setting, first select a setting other than "Execute View Definition Scripts" in the "Execution Mode" settings.
tip
- You can create richer expressions by specifying HTML as the content format and using a script to generate dynamic HTML content.
Using Model-Specific Scripts
To write a script for each model and generate and display dynamic content specific to that model, follow these steps:
Instructions
- Switch to the Markdown Editor view for the target model.
- Display the Inspector and switch to the Markdown Editor tab.
- Configure the Markdown Editor tab as follows:
- Specify the field where you want to write the script in the Fields setting.
- Select Scripts can be defined per view in the Execution Mode setting.
- Click the Edit icon in the upper right of the Markdown Editor view to open the script editing area and write your script.
- Click the Script Execution Mode toggle icon on the toolbar above the script editing area to turn it ON. The Markdown generated by the script will be displayed in the Markdown Editor view.
Sample Script
//Target Model
var targetModel = (IModel)Params["TargetModel"];
var sb = new StringBuilder();
//Child Models
var models = targetModel.GetChildren();
foreach (var model in models)
{
sb.AppendLine(@$"* [{model.Name}](modelId://{model.Id}) ");
}
sb.AppendLine(@$"
Number of Models: {models.Count}");
//returns
var ret = $@"
## {targetModel.Name}
{sb}
";
return ret;