We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37914
    • 89 Posts
    Quote from: Bruno17 at Jan 06, 2015, 11:05 AM
    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]]
    

    WOW Bruno.

    This works exactly like I imagined it would.
    Thanx!
    Can I make a donation somewhere?
      • 37914
      • 89 Posts
      Thank you very much for your reply Viener, but Bruno17's reply is exactly what I needed. But thanx for your time anyways..
      • Thank you for the excellent recipe, mdehaan and Bruno! http://modxcookbook.com/basics/resources/extract-part-of-content.html
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 37914
          • 89 Posts
          Quote from: sottwell at Jan 06, 2015, 01:25 PM
          Thank you for the excellent recipe, mdehaan and Bruno! http://modxcookbook.com/basics/resources/extract-part-of-content.html

          I can go to the page from your link.
          But I can't find it trough your navigation.
          Maybe I'm not looking at the right place, or maybe you aren't done adding/writing....
          • thank you for that, I'd forgotten to edit the Menutitle!

            I'm using an unpublished resource with the content structure I need, duplicating it for each recipe. I haven't gotten Content Blocks under control yet, but once I do I won't need to duplicate an already structured resource. Content Blocks will provide the sections I need - intro, question, answer, discussion.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org