snippet 'extractH1fromContent':
<!--?php $html = $modx--->resource->get('content'); $tag = 'h1'; preg_match_all('|<h[^>]+>(.*)</h[^>]+>|iU', $html, $headings); foreach ($headings as $heading){ $fullnode = isset($heading[0]) ? $heading[0] : ''; $text = isset($heading[1]) ? $heading[1] : ''; if (strstr($fullnode,'h1')){ $modx->setPlaceholder('h1.fullnode',$fullnode); $modx->setPlaceholder('h1.text',$text); $html = str_replace($fullnode,'',$html); break; } } $modx->setPlaceholder('cleancontent',$html);
[[extractH1fromContent]] [[+cleancontent]] [[+h1.fullnode]]
Thank you for the excellent recipe, mdehaan and Bruno! http://modxcookbook.com/basics/resources/extract-part-of-content.html