Teeknow
Teeknow

Reputation: 1015

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.

Upvotes: 5

Views: 1240

Answers (3)

Martin Davies
Martin Davies

Reputation: 4456

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.

Upvotes: 3

Charlie Afford
Charlie Afford

Reputation: 86

Do you mean in the experience editor? We had the same problem when trying to index pages for search that were developed in the experience editor. What we did is made a HttpRequest to the page, retrieved the html, removed all the tags and indexed the content as _content. When we then wanted to do a key word search we then matched against _content. Hope this helps. Charlie

Upvotes: 0

Dylan McCurry
Dylan McCurry

Reputation: 11

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.

Upvotes: 1

Related Questions