Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider Follow Me On Twitter
Escaping ASP.NET Tags in Code Smith Templates

I love to generate code, I have code templates for Code Smith that are the equivalent of a mold for a machine shop. I use them to create thousands upon thousands of lines of code each week, so I guard them with my life and update them almost as often as I update my applications I think.

Code Smith uses the same syntax as ASP.NET to build code generating templates. So one thing I had to learn to overcome was dealing with <%  %> tags in Code Smith, or escape ASP.NET tags in my Code Smith templates. The answer is to use a %% so it would look like <%% %%>.

<td class="ListTitle">
    <a href='<%%# String.Format("AddEdit<%= sTableName %>.aspx?<%= sTableName %>id={0}", Eval("<%= sTableName %>Id")) %%>'>
        <%%#Eval("<%= sTableName %>")%%></a>
</td>
Posted: Friday, October 24, 2008 9:50 PM

by Chris Love

Comments

Jules Wensley said:

Thanks Chis, Great tip (couldn't find it on the codesmith forums).
# April 16, 2010 6:41 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS