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:
- Set the rendering’s Rendering Contents Resolver to the out-of-the-box
Context Item Resolverso the rendering is loaded with the context item rather than the datasource item (which would be null in this case) OR
withSitecoreContextwithin 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 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.