Contrib ImageField Module

Topics: General, Troubleshooting, Writing modules, Writing themes
Jun 20, 2011 at 3:46 PM

So I have downloaded, installed and used the Contrib ImageFeild Modue within a custom content type. All works well except for when I try to resolve the image url in my content type view.

For example, in my debugging of the custom view template I assign a variable to the FileName property of my content type which has the value "~/media/default/bio/biophoto/myimage.jpg", this is exactly what I want to render but what does render is this http://mysite/~/media/default/bio/biophoto/myimage.jpg what am I missing here. I did allow the module to do a default install so I was assuming it would path correctly. Also running orchard.web as a virtual under local IIS but it is not the default site. Am I missing something here? I could strip the "http://mysite" out but that doesnt seem to me to be the correct way to handle this. Am I configured incorrectly or other. Any help is appreciated.

Thanks.

(~/themes/mytheme/views/items/content-bio.cshtml) - the view template

@using Orchard.Utility.Extensions;
@using Orchard.ContentManagement;

@{

string biophoto = Model.ContentItem.Bio.BioPhoto.FileName;
var photo = new HtmlString(biophoto);

  }

 <div class="myclass" style="display:block; width:122px; padding-left:3px; padding-bottom:25px;">
            <img src="@photo" alt="" />
        </div>

Coordinator
Jun 20, 2011 at 4:24 PM

You need to call Url.Content like this: 

@{
string biophoto = Model.ContentItem.Bio.BioPhoto.FileName;
}

<div class="myclass" style="display:block; width:122px; padding-left:3px; padding-bottom:25px;">
<img src="@Url.Content(biophoto)" alt="" />
</div>

Jun 20, 2011 at 4:40 PM

Perfect, thanks.