relative urls and css in episerver

Vote:
 

Hi I'm working on my first episerver project and have a problem regarding a css based design where relative urls are required (i.e. in the background-image url).

I dont want to use the filesystem with every little design image in my site so I just have a folder in the root named Images. 

My questions are:

Does episerver have a way to make a relative path to the root of the application?

How can I obtain the rewritten path as fx "http://localhost:6666/da/public-root/page2/"?

When i request the url i get the actual url: http://localhost:6666/page2.aspx?id=19&epslanguage=en instead.

Hope someone can help

Kind regards

Sune Fengel 

#19647
Apr 22, 2008 16:30
Vote:
 

Hi,

i do not really know what you actually mean but you can use

background-image: url(images/framework/header.png);

 

for your backround images in css. But you will probably have to keep your css files together with you images folders.

 /Styles/images/...

and

/Styles/style.css

Please look at the publictemplates or the demo templates for examples. If you would like to obtain the rewritten path you could turn the Friendly URL on in web.config. If you are developing directly in Visual Studio and are using an SDK Project you will have to insert some sections in web.config.
But then again you can look att the demo package or install a site via the manager and look at the web.config in that project for some examples.

Best Regards/Eric

#19650
Apr 22, 2008 21:12
Vote:
 

Hi thanx for the reply.

I wrote a method to lead back to the root of the site with the Request.RawURL, which as it turned out, was the url data I was looking for.

The problem arose because I have some usercontrols with the css in the actual aspx page. but of course I could have all the css files in a css folder :)

 

- Sune 

#19672
Apr 24, 2008 11:15
Vote:
 

Hi,

I have a similar question. I'd like a way to let the editors choose a background image for a page. I'm sure it must be very simple but I'm not succeeding.

My attempt: I added a property to the page called 'backgroundImage' with property type ContentReference (I've tried several other types with no better results).

Now, all I have to do is get hold of the path to that image in the .cshtml page. If I put @Html.DisplayFor(m => m.backgroundImage) it generates a nice little anchor with href = '/globalassets/koala.jpg'. But I can't figure out how to get at that path so I can stick it into a 'style=background-image:@whatever'.

I put a breakpoint in the .cshtml to examine the contents of the Model and can't figure out where this information is hidden. 

Any enlightenment would be greatly appreciated.

--Pete

#89001
Edited, Aug 05, 2014 16:23
Vote:
 

Solved it this way:

 1. add extra [Ignore]d property to model for backgroundImagePath

 2. in the controller: currentPage.backgroundImagePath = UrlResolver.Current.GetUrl(currentPage.backgroundImage);

 3. use that property in .cshtml

I'd like to know if there's a better way.

#89054
Aug 06, 2014 12:16
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.