Instead of this .tt:
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".txt" #>
<#@ assembly name="System"#>
<# message = "hello world" ; #>
blah blah blah etc. very complex example with embedded expression like
<#=message#>
I'd like to have an output function that would return the output blah blah etc.:
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".txt" #>
<#@ assembly name="System"#>
<#output();#>
<#+ output() { #>
blah blah blah etc. very complex example with embedded expression like
<#=message#>
<#}
#>
Of course the syntax above is not correct. How to do this ?
This is an alternative solution not using class feature blocks <#+ ... #>
.
Using a lambda expression inside usual statement blocks <# ... #>
allows defining a local function as follows:
<#@ template language="C#" #>
<#@ output extension=".txt" #>
<# Action output = () => { #>
loooooooong text <#= "message" #>
<# }; #>
<# output(); #>
This template produces the output below:
loooooooong text message
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With