views:

72

answers:

3

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">
A: 

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 C
default approach.Not sparkish
Quintin Par
+4  A: 

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>
kouPhax
Or <script if='!IsDebug' type="text/javascript"></script> as the case may be in you original question :-P
kouPhax
+2  A: 
##if DEBUG
<script type="text/javascript"></script>
##endif

Should work.

John Gietzen
I think he wanted the inline condition expression style but this approach is certainly much more straightforward
kouPhax