Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore Get Rendered Html

Is there a way to get the rendered html of an item based on it's presentation values from the code behind? In a recent project this needed to be done and we are currently scraping our own site with another request which seems wasteful.

like image 316
Teeknow Avatar asked Sep 25 '22 19:09

Teeknow


2 Answers

Unfortunately I don't think there's a clean way of achieving this. A usercontrol relies heavily on running through the page lifecycle and therefore an HTTP request. You also often have dependencies on various parts of the Sitecore context which get built up during the course of a request.

With MVC you have more options because you can call the Render method directly. But you still have to correctly build up the model in the first place. So you'll probably still have difficulties.

As you said it seems wasteful, but screen scraping is the usual way to achieve it. I know of a couple of existing modules that use this approach for indexing page content.

  • sitecore-html-crawler
  • eFocus websearch module for Sitecore
like image 181
Martin Davies Avatar answered Oct 12 '22 10:10

Martin Davies


I usually open a web request and fetch the item. If I only need a specific placeholder, I restrict access to it via something like ?mode=placeholder-name.

This is particularly useful when crawling the site and wishing to cache HTML in your search index.

like image 39
Dylan McCurry Avatar answered Oct 12 '22 11:10

Dylan McCurry