Sitecore Get Rendered Html

Is there a way to get the displayed html of an element based on its view values ​​from the code behind? In a recent project, this needed to be done, and we are currently cleaning our own site with another request that seems wasteful.

+5
source share
3 answers

Unfortunately, I do not think there is a clean way to achieve this. User control is heavily dependent on the execution of the page life cycle and, therefore, the HTTP request. You also often have dependencies on the various parts of the Sitecore context that are created during the request.

With MVC, you have more options because you can directly call the Render method. But you still need to correctly create the model first. So you are probably still having difficulty.

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

+3
source

Usually I open a web request and select an item. If I need only a specific placeholder, I will restrict access to it through something like ?mode=placeholder-name .

This is especially useful when crawling a site and wanting to cache HTML in your search index.

+1
source

Do you mean in the experience editor? We had the same problem when trying to index search pages that were developed in the experience editor. We did an HttpRequest on the page, fetched the html, removed all the tags, and indexed the content as _content. When we then wanted to do a keyword search, we then matched _content. Hope this helps. Charlie

0
source

Source: https://habr.com/ru/post/1239440/


All Articles