0

Is it possible to get the few renderings' (present on the page) contents dynamically, but the catch is like I don't want HTML instead I want the field values which are used to be displayed on the page.

The main purpose is that I have to send all fields' data to an API.

Envrionment: Sitecore 8.2 update 1 (MVC)

  • Somethings like JSON, JSS? – Jan Bluemink Jun 26 at 8:03
  • The Layout Service which is delivered with JSS will help you. – Artsem Prashkovich Jun 26 at 8:57
  • @JanBluemink something like JSON, as I am using Sitecore 8.2 update 1 – Prashant Tomar Jun 26 at 10:15
  • Are you using WebForms or MVC? – Matthew Dresser Jun 26 at 10:21
  • @Matthew Dresser, I am using MVC – Prashant Tomar Jun 26 at 10:53
0

If you are using MVC, you could simply build a controller rendering and format the cshtml markup as JSON (depending on where this component is placed in the rendering/placeholder structure of your page). You could also make it output a <script> block with a variable initialised to the required JSON data.

Edit

After realising that you want the output from multiple renderings as JSON from a single request, this would need a different approach. You could make a JSON device along with a JSON-specific layout so for <hostname>/my-page you could then request <hostname>/api/my-page which would render the same page (and hence renderings) but using the JSON device (and hence JSON layout and renderings).

  • If I want those few renderings' data in one go programmatically, instead of loading the page in the browser, then how can I achieve that? Assume that I have to send the data to an API's response. – Prashant Tomar Jun 26 at 11:05
  • I see. You want the output of multiple renderings in one API call. Do those renderings also need to be able to render HTML for initial page load as well? – Matthew Dresser Jun 26 at 12:41
  • No HTML for initial page load. Only need to show the data of the fields which are being consumed by those renderings. – Prashant Tomar Jun 26 at 15:27
0

Below are the steps what we followed:

All these steps have been done in the computed index field.

  1. Captured all the renderings (present in the final layout) present in specific placeholders, because most of the data renderings are present in a specific placeholder.

  2. We checked if there is any data source, if yes, then get the data from the data source item. For getting the data source item's data we created the setting in the Sitecore multi-list where user can select the field from which he wants to pick the data.

  3. When all the data has been captured then we also gathering the data from the page itself. We have set same for the pages also like, to select the fields for which the client wants the data.

  4. When we are getting the data we are putting all the data in the string builder and passing that large string in the computed filed index. So that, at the time of requesting for a page we can search the index and get the data from the index (Becuase this will be fast instead of getting data directly from the Item).

NOTE: I have set up the field selection in the Sitecore but you can thing more customizable according to your need.

Your Answer

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

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