0

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

<script if='x==5' type="text/javascript">
Quintin Par
  • 15,862
  • 27
  • 93
  • 146

3 Answers3

4

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>
James Hughes
  • 6,194
  • 4
  • 31
  • 44
2
##if DEBUG
<script type="text/javascript"></script>
##endif

Should work.

John Gietzen
  • 48,783
  • 32
  • 145
  • 190
-1

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!

Russ Clarke
  • 17,511
  • 4
  • 41
  • 45