Images not displaying from theme layout (Orchard CMS)

wegelagerer picture wegelagerer · Mar 29, 2011 · Viewed 10.3k times · Source

I'm trying to create theme for Orchard CMS. The template I have wasn't made for it so I have some troubles displaying images from Layout.cshtml.

This is the current folder structure on my web server (theme folder structure only):

Theme/Content/Images/Image.jpg Theme/Views/Layout.cshtml Theme/Styles/Site.css

The following line doesn't display image (located in Layout.cshtml):

<img src="../Content/Images/bgBig.jpg" alt="Big background image" />

However, this line does display the image (located in Site.css):

background-image:url('../Content/Images/bgLines.png');

I believe the problem is that Layout.cshtml doesn't display the image from Theme/Views/Layout.cshtml, but from the other location. If someone knows what would be that location or how to override it I would be thankful.

Answer

Tiago picture Tiago · Mar 20, 2012

I might be a little late, but this may be of help to others.

To get the current theme and then build an dynamic path (as opposed to an absolute path) use this:

WorkContext.CurrentTheme: Gets the current working theme ExtensionDescriptor.

Then give it to the Html.ThemePath URL builder: Ex.

Html.ThemePath(WorkContext.CurrentTheme, "/Content/Images/SomeImage.png")

Have fun!

Best regards, Tiago.