We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9359
    • 128 Posts
    Hello everybody,
    I would like to know if there is a way to take the first picture included in content area of a resource without using TV. is possible?

    thx
      "Destiny is not a matter of chance, it's a matter of choice"
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You could make a plugin to parse the $modx->documentObject['content'] and pull out the first image tags, using a regular expression or a couple of PHP functions. http://w-shadow.com/blog/2009/10/20/how-to-extract-html-tags-and-their-attributes-with-php/

      Put it in a placeholder using the setPlaceholder API function
      $modx->setPlaceholder('myImageTag', $img-src);

      and then you can use the placeholder wherever you want it. [ed. note: sottwell last edited this post 15 years ago.]
        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
        • 9359
        • 128 Posts
        Hi sottwell,
        many thx for your reply.
        I try but does not seem easy :-(

        Fabry
          "Destiny is not a matter of chance, it's a matter of choice"
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          My advice would be to use an image TV, even if the same image is inserted at random points in the content.
            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