0

I have component that has no explicit datasource because I want it to get its field values from the route item (which also happens to be the Sitecore context item). What would be the preferred method of wiring that up?

Two options stand out:

  1. Set the rendering’s Rendering Contents Resolver to the out-of-the-box Context Item Resolver so the rendering is loaded with the context item rather than the datasource item (which would be null in this case) OR
  2. Import withSitecoreContext within the component and access the data via props.sitecoreContext.route.fields (docs on Sitecore context access)

One thing I noticed is that with both approaches, you lose the custom experience editor button to easily open up a window to edit all of the item's fields:

Context Menu w/ Explicit Datasource

context menu w/ explicit datasource

Context Menu without Explicit Datasource

context menu without explicit datasource

Otherwise, both methods seem to function fine and I can edit the fields in the Experience Editor without any issues. Are there any major drawbacks or advantages to either approach? I suppose that the second method may be "safer" in case the context item ever changes, but I can't see that happening.

One important area to consider would be if this rendering had a placeholder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.