RazorEngine Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Require PSNuGet<https://github.com/altrive/PSNuGet> | |
Use-NuGetPackage RazorEngine -Version 3.6.6 -Verbose | |
# テンプレート | |
$template = @' | |
Hello @Model.Name! Welcome to Razor! | |
@if (Model.ShowDetail) { | |
@:Plain Text!! はろー | |
} | |
@foreach (var item in Model.Array) { | |
@:Item value: @item => @item | |
} | |
'@ | |
# モデル | |
$model = [pscustomobject] @{ | |
Name = "F#hoge" | |
ShowDetail = $true | |
Array = @(1; 2; 3;) | |
} | |
#Modelに[pscustomobject]を使う場合は事前コンパイルが必要(でないと初回にModel渡した際に必要なプロパティが存在しない旨のエラーが発生する) | |
$cacheKey = "TestTemplate" | |
[RazorEngine.Razor]::Compile($template, $cacheKey) | |
[RazorEngine.Razor]::Parse($template, $model, $cacheKey) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment