Quinn-Interactive / silverstripe-seo

An all-in-one SEO module for SilverStripe 4.1+
BSD 3-Clause "New" or "Revised" License
33 stars 20 forks source link

possible solution for rendering when using Elemental #55

Open jellygnite opened 4 years ago

jellygnite commented 4 years ago

I noticed that the analysis in PageHealthExtension didn't take into account any Elemental blocks. I couldn't see how you would use the seoContentFields configuration so I tried rendering with the current theme.

public function getRenderedHtml() {
... 
$current_themes = SSViewer::get_themes();  // get current CMS theme
Requirements::clear(); // we only want the HTML, not any of the js or css
SSViewer::set_themes(SSViewer::config()->uninherited('themes'));
$this->renderedHtml = $controllerName::singleton()->render($this->owner);
Requirements::restore(); // put the js/css requirements back when we're done
SSViewer::set_themes($current_themes);  // reset current CMS theme when we're done
...
}
Fremmedkar commented 3 years ago

You can use seoContentFields by casting the result of getElementsForSearch in ElementalPageExtension as Text in your Page class

private static $casting = [
    'ElementalContent' => 'Text'
];

public function getElementalContent()
{
    return $this->hasExtension(ElementalPageExtension::class) ? $this->getElementsForSearch() : '';
}

public function seoContentFields()
{
    return [
        'Content',
        'ElementalContent'
    ];
}