Namita Roy
Namita Roy

Reputation: 265

Sitecore FieldRenderer to return relative path

I am using following line of code to render image:

string html = Sitecore.Web.UI.WebControls.FieldRenderer.Render(
                                            Item,
                                            this.Field,
                                            renderParameters + "&disable-web-editing=" + this.DisableWebEditing.ToString()); 

Following string is assigned in html:

<img src="http://localhost/~/assets/images/widgets/contact.png?bc=White&amp;h=130&amp;la=en&amp;w=130" width="130" height="130" />

Is there any way so that src of image is relative path?

Upvotes: 2

Views: 408

Answers (1)

Marek Musielak
Marek Musielak

Reputation: 27132

Assuming that your application doesn't have any customizations, FieldRenderer uses MediaUrlOptions to know how to generate the url.

MediaUrlOptions uses Settings.Media.AlwaysIncludeServerUrl to determine whether the full server url should be included or not.

Check your setting in the configuration and set it to proper value:

<!--  MEDIA ALWAYS INCLUDE SERVER URL
        If true, Sitecore will generate absolute URLs when it uses the MediaProvider API and/or the link provider to render media URLs.
        If blank, Sitecore will use the same value as the alwaysIncludeServerUrl attribute from the link provider.
        Default value: "" (use the value from the link provider)
  -->
<setting name="Media.AlwaysIncludeServerUrl" value="" />

Upvotes: 1

Related Questions