This question has been answered by Bruno17. See the first response.
You could use a plugin to parse the content and get the <h1> DOM element and its content, providing there is only one H1 tag in the content. Then you could set the value of a placeholder with it.
To be honest, I don't see how this is going to work well. What, exactly, are you doing? If you need a dynamic value, use a TV. That's what they are for.</h1>
and search for 'strip_selected_tags'
here:
http://php.net/manual/de/function.strip-tags.php
Quote from: mdehaan at Jan 06, 2015, 09:46 AMI'm looking for a Snippet/Output Modifier to:
- Get the value of a H1 tag from the [[*content]]
- Remove the H1 tag including its value
- Output the value to a placeholder
I know we can get any value from a tv or the pagetitle field, but for this project the H1 has to be inside the [[*content]].
Any help would be much appreciated.
>>Get the value of a H1 tag from the [[*content]]
- Does it have to be exactly [[*content]] or it may be [[$content]] (a chunk)?
>>Remove the H1 tag including its value
- Remove and place in its place what? Just leave an empty space?
- Removes who/what: an end user, a script?
some start-points for a snippet:
http://kaspars.net/blog/web-development/regex-extract-headings-h1-h2-h3-from-html
and search for 'strip_selected_tags'
here:
http://php.net/manual/de/function.strip-tags.php
<?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]]
Quote from: sottwell at Jan 06, 2015, 09:53 AMYou could use a plugin to parse the content and get the <h1> DOM element and its content, providing there is only one H1 tag in the content. Then you could set the value of a placeholder with it.
To be honest, I don't see how this is going to work well. What, exactly, are you doing? If you need a dynamic value, use a TV. That's what they are for.</h1>
What I'm trying to achieve is to have the end user use the H1 tag from the WYSIWYG editor from the main content field.
This is easier to understand for them.
The problem is with the frontend.
Sometimes we want to have the H1 tag inside an other DIV than the one the other page content is in.
I know it would be much easier to use a TV for this, but would this be a bad idea or hard to achieve?