Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore Field Renderer - add markup inside rendering

Tags:

sitecore

As part of an SEO enhancement project, I've been tasked with adding the following property inside the markup for the image that the field renderer is generating on the page:

itemprop="contentURL" - before the closing tag.

<sc:FieldRenderer ID='FieldRenderer_MainImage' Runat='server' FieldName='Homepage Image'
    CssClass="_image" Parameters="w=150" itemprop="contentURL" />

When I tried to place this inside the Field Renderer, or add it as a "parameter" - it doesn't work.

Is there another way to do this, without having to create a control file and generate the output in the code-behind?

like image 531
sean Avatar asked Feb 20 '26 22:02

sean


2 Answers

You need to use the "Parameters" property for setting extra properties on both the and control.

You can to it like this :

<sc:FieldRenderer ID="PageImage" runat="server" FieldName="ContentImage" Parameters="ControlType=C4Image&rel=relString" />
<sc:Image ID="SCPageImage" runat="server" Field="ContentImage" Parameters="ControlType=C4Image&rel=relString" />

That will be rendered like this :

<img width="1232" height="637" controltype="C4Image" rel="relString" alt="" src="~/media/Images/DEMO backgrounds/background2.ashx">

Note: This works in 6.5 and 6.6 - not sure which version is being used in this question.

like image 98
M.R. Avatar answered Feb 22 '26 11:02

M.R.


Couldn't this be done by extending the RenderField pipeline? You could potentially decompile (using Reflector or ILSpy) the GetImageFieldValue and add your own logic to adjust the output from the ImageRenderer?

Reference Sitecore.Pipelines.RenderField.GetImageFieldValue.

like image 29
nickwesselman Avatar answered Feb 22 '26 12:02

nickwesselman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!