1

I have a rendering parameter used all over my site with a field called breakpoint and a standard value of medium. On a specific page template, I want that value to be large when the rendering is added to the page.

I am looking to avoid changing it on a save event, so the editor can change it if they want. I am just looking for a new default value without creating all new renderings and associated rendering parameter templates.

1 Answer 1

0

Think it might be as simple as checking if the field is pulling in standard values. If it is then you know nothing has been selected, so display your second default value (if on correct template).

Please try this and see if it works for you (apologies I haven't had a chance to test it out):

var parameters = RenderingContext.Current.Rendering.Parameters;

Sitecore.Data.Fields.Field breakpointField = parameters["breakpoint"];

string breakpointValue = breakpointField?.Value;

if(RenderingContext.Current.Rendering.Item.TemplateName == "specific page template" && breakpointField.ContainsStandardValue)
{
  breakpointValue="large";
}

Reference: https://doc.sitecore.com/xp/en/developers/103/sitecore-experience-manager/determine-if-a-field-contains-standard-values.html

2
  • I think this would need to be used in an save event. I was hoping on doing it in a UI pipeline as the rendering is added to the page. Kind of around the same place we work with a rendering datasource as it is added.
    – Chris Auer
    Commented Dec 11, 2023 at 14:08
  • I dont think so, if you place it in the view it would override the value being used within the view. It wouldnt set it, just like anything that uses a standard value doesnt actually have a value set for the field. If an author did set the value, then that would be used moving forward. Commented Dec 11, 2023 at 15:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.