views:

30

answers:

2

Hi new to spark so this should be simple.

I'm converting an old webfoms page to mvc using spark. I want to use the Base.Application to make up the src of a url

original markup

<img alt="" src="<%= Base.ApplicationPath %>images/screenshots/myImage.jpg" />

I've tried this in spark

<img alt= src=${  Base.ApplicationPath }+">images/screenshots/myImage.jpg" />

but no joy.

How do i do this in spark?

+1  A: 

Slight tweak of the syntax has sorted it.

<img alt="" src="${Base.ApplicationPath}images/screenshots/myImage.jpg" />
John Nolan
+2  A: 

Hey Johnno,

Not sure if you're aware of this, but Spark has a DefaultResourcePathManager that will automatically locate the Site Root if you prefix the resource with a tilde, so this should work just fine, and looks neater.

<img alt="" src="~/images/screenshots/myImage.jpg" />

There's an added bonus to using this technique as well....hold on to your shorts! Without changing your view, simply by making sure you use the tilde convention, you can dynamically redirect requests for your static resources to a content delivery network (CDN) or a completely different location - even an embedded resource inside a Spark Module .dll you compile for dll drop in deployment.

For example, to hook it up to a CDN, all you'll need to do is add the following kind of thing to your Spark Settings:

<resources>
  <add match="/content/images" location="http://mycdn.com/youraccount/images"/&gt;
  <add match="/content/css" location="http://mycdn.com/youraccount/css"/&gt;
  <add match="/content/js" location="http://mycdn.com/youraccount/js"/&gt;
</resources>

...and from then on those resources will be fetched from the new location instead. This is great for scenario testing locally, and the deploying to the cloud later.

RobertTheGrey