We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12013
    • 61 Posts
    I am sure I am being really stupid here but what the heck. I am using the RandomImage snippet and it is doing what it is required to do, but is there a way to tell it to display as a background image.

    Thanks in advance for your help
      • 12423
      • 9 Posts
      I did similar thing. I needed to have random banner pictures.
      So I created one folder with pages which contain HTML piece of code with (IMG markup). Every picture = one document.

      And in the template you can use DITO snippet with the following parameters: parent=’ID of your folder’, display=1, randomize=1, total=all.

      If you are setting backgroundimage in CSS style, you should use CSS style as a document in MODx using DITO snippet as well.

      This could be used for any random requests without ad-hoc snippets - random jokes, random pictures, random quotations, etc.

      HTH.

      P.
      • I always thought using Ditto and the database like that was a bit of an overkill for something as simple as grabbing a random image from a given folder, though.

        To use it for a background image, have the CSS that specifies the background image for a given element in a <style> block in your template head, and use the snippet there.
          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
          • 12423
          • 9 Posts
          Quote from: sottwell at Sep 11, 2008, 11:49 AM

          I always thought using Ditto and the database like that was a bit of an overkill for something as simple as grabbing a random image from a given folder, though.

          To use it for a background image, have the CSS that specifies the background image for a given element in a <style> block in your template head, and use the snippet there.
          You’re right it is more than neccesary for this particular purpose. I like it simply because it opens many other possibilities and it is pretty flexible. Additionally, I am trying to avoid using of "many" other snippets which may cause problems during the upgrade in future?

          You know, I like MODx - it offers so many ways:)