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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With