Developer forum

Forum » Templates » @Include svg
René Poulsen
Reply

Hi,

I've created an item where I have to choose an icon. The icon is a svg file and instead of just using it in an img tag, I want to have the svg inline.

I tried using like this:

@{

string icon = GetString("Item.Icon")

}

@Include("@icon").

This is not working. I get this error: Include file icon.svg not found in Templates/Desings/design/Paragraph/template.cshtml.

I've tried "dotting" out of the paragraph folder, but without any luck.

Does anyone know if this is somehow possible to do?

 


Replies

 
René Poulsen
Reply

Just continuing from another thread: http://developer.dynamicweb.com/forum/templates/razor-include-file-from-ancestor-folder.aspx

 

My plan is offcourse to use DW functionality as our customer needs to be able to do this - so they just have to be able to choose an icon in a dropdown. If it's not possible to do, then there's nothing to do about it. I was just wondering why it didn't work when getting the Item.Icon - because it's working with a hardcoded path which is exactly the same as the value in the Item.Icon.

I just want my SVG inline. Theres a lot of reasons for that - but that's not the discussion right now :-)

I've tried putting @using System.Web.Mvc, but I still get the errors that Html, File and Server does not exist in the current context.

 
Bogdan Ciocsan
Reply
This post has been marked as an answer

Hi Rene

Try using the following code: 

@{
    string icon = GetString("Item.Icon");
}

@System.IO.File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath(icon))

Best regards

Bogdan 

Votes for this answer: 1
 
René Poulsen
Reply

Perfect! It works.

Thank you Bogdan!

 

You must be logged in to post in the forum