RainLab\Pages\Classes\Snippet::processPageMarkup PHP Method

processPageMarkup() public static method

Parses the static page markup and renders snippets defined on the page.
public static processPageMarkup ( string $pageName, Cms\Classes\Theme $theme, string $markup ) : string
$pageName string Specifies the static page file name (the name of the corresponding content block file).
$theme Cms\Classes\Theme Specifies a parent theme.
$markup string Specifies the markup string to process.
return string Returns the processed string.
    public static function processPageMarkup($pageName, $theme, $markup)
    {
        $map = self::extractSnippetsFromMarkupCached($theme, $pageName, $markup);
        $controller = CmsController::getController();
        $partialSnippetMap = SnippetManager::instance()->getPartialSnippetMap($theme);
        foreach ($map as $snippetDeclaration => $snippetInfo) {
            $snippetCode = $snippetInfo['code'];
            if (!isset($snippetInfo['component'])) {
                if (!array_key_exists($snippetCode, $partialSnippetMap)) {
                    throw new ApplicationException(sprintf('Partial for the snippet %s is not found', $snippetCode));
                }
                $partialName = $partialSnippetMap[$snippetCode];
                $generatedMarkup = $controller->renderPartial($partialName, $snippetInfo['properties']);
            } else {
                $generatedMarkup = $controller->renderComponent($snippetCode);
            }
            $pattern = preg_quote($snippetDeclaration);
            $markup = mb_ereg_replace($pattern, $generatedMarkup, $markup);
        }
        return $markup;
    }

Usage Example

Example #1
0
 public function getProcessedPlaceholderMarkup($placeholderName, $placeholderContents)
 {
     if (array_key_exists($placeholderName, $this->processedBlockMarkupCache)) {
         return $this->processedBlockMarkupCache[$placeholderName];
     }
     $markup = Snippet::processPageMarkup($this->getFileName() . md5($placeholderName), $this->theme, $placeholderContents);
     return $this->processedBlockMarkupCache[$placeholderName] = $markup;
 }
All Usage Examples Of RainLab\Pages\Classes\Snippet::processPageMarkup