I am using Sitecore's render method to construct the query strings for image assets, but I have a small challenge parsing custom parameters into the rendered query string in the HTML.

It seems that the render pipeline has some logic to interpret certain parameters and adds them to the query string, but anything else it adds as an attribute on the img tag (example below).

if you add a parameter such as "h" for height:

@imageField.Render(parameters: "h=200")

output html:

<div class="image ">
  <img src="/~/media/cvi-2-color-icons/icon-faq-384x140.png?h=200" alt="" height="200">

However, if I write something like "optimize":

@imageField.Render(parameters: "optimize=200")

output html:

<div class="image ">
  <img src="/~/media/cvi-2-color-icons/icon-faq-384x140.png" alt="" optimize="200">

Is there a good way to override this behavior or hook into the pipeline and allow additional parameter strings?

  • 1
    Is .Render an extension method or are you using another framework/mapper?
    – josedbaez
    Dec 13, 2018 at 13:05
  • An extension method. It will do down and call the renderField pipeline at some point. But I am just looking for at method to parse additional parameters and have them appended to the query string through the pipeline, like if I used: @Html.Sitecore().Field("Image", item.InnerItem, new { h="120", format="jpg"}) (Where "format" isn't recognised as a parameter, but is only set as an attribute)
    – Mark Wulff
    Dec 14, 2018 at 8:06


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.