Glass, ForceRenderField, and the RenderField pipeline

I was recently doing some token replacement of field values using a processor that I was adding to the RenderField pipeline. The problem was, it wasn’t running in Glass. Debugging in Visual Studio, the pipeline was never hit. Standard Sitecore rendering of the field was fine, but Glass – nope.

After much scratching of head and Googling, I found this on Github:  https://github.com/mikeedwards83/Glass.Mapper/issues/98

So, for efficiency…

The renderField pipeline is only called during edit mode for all field types except Rich Text.

Good news though…

I think we added the field setting SitecoreFieldSettings.ForceRenderField which forces a string field to use the renderfield pipeline.

Right, so can we use that? Yes, we can. Here is an example model:

That causes the RenderField pipeline to run when Glass is rendering the Content field.

And suddenly my token replacement started working. It’s a bit of a pain having to tag all the relevant fields up with this ‘ForceRenderField’ attribute, but it’s pretty easy, and using a pipeline makes sense.

 

 

Advertisements
Glass, ForceRenderField, and the RenderField pipeline

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.