Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of <#= #>

Reading Code Generation and T4 Text Templates and I found this syntax <#= DateTime.Now #>

<html><body>
 The date and time now is: <#= DateTime.Now #>
</body></html>

How is it different from <%= DateTime.Now %> or <%# DateTime.Now %>.

Google search showed nothing

like image 225
codingbiz Avatar asked Oct 06 '22 23:10

codingbiz


1 Answers

I can't claim to be really familiar with T4 text templates, but it appears the difference is between design/build time code generation (which can include executable statements) and runtime code execution.

So <#= #> evaluates an expression within a template that is used to generate a file.

And <%= %> executes the code within the block and writes it to the output stream. This will be JIT-compiled when the page is first executed, but the point is that it denotes a block of code to execute when the page runs, not during generation of a templated file.

The third form, <%# %> denotes a databinding expression, also evaluated when the page executes.

Expression control blocks

An expression control block evaluates an expression and converts it to a string. This is inserted into the output file.

Expression control blocks are delimted by the symbols <#= ... #>

For example, the following control block causes the output file to contain "5":

<#= 2 + 3 #>

Source: http://msdn.microsoft.com/en-us/library/bb126478

like image 141
Tim M. Avatar answered Oct 13 '22 11:10

Tim M.