I have some scripts which need to be included only in the release version. Stuff like google analytics, quantserve etc.
The typical way in asp.net mvc world is to wrap a
#if DEBUG
#endif
How do I do it the sparkish way. Like
<s开发者_开发问答cript if='x==5' type="text/javascript">
You could specify a custom Base Page for the Views.
public abstract class BaseSparkView<TModel> : Spark.Web.Mvc.SparkView<TModel> where TModel : class
{
public bool IsDebug
{
get
{
#if DEBUG
return true;
#else
return false;
#endif
}
}
}
Then in your web.config create the spark section
<spark>
<pages pageBaseType="BaseSparkView" />
</spark>
And finally in your page you could do this...
<script if='IsDebug' type="text/javascript"></script>
##if DEBUG
<script type="text/javascript"></script>
##endif
Should work.
Just a suggestion, what if you do this:
<% #if DEBUG %>
<script if='x==5' type="text/javascript">
<$ #endif %>
Note the space between % and #. Don't know if this will work or not, has to be worth a try!
精彩评论