We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6561
    • 139 Posts
    I’m using the RandomHTML snippet to fetch html chunks from the filesystem on folder assets/randomhtml . I would like to know if it is possible to have a directory where in each page you create, it exports the HTML code of the ’content’ field to a specific folder on the filesystem.

    For example
    - There is a Folder ’Promotions’
    - In that folder, if you create a document with title ’promotion-one’, on saving the document the html code for the ’content’ field gets exported to a file called ’promotion-one.html’
    - As a result, the RandomHTML snippet will display a random HTML page from that directory.

    This would provide an easy way for content managers to add their own promotions, banners, teasers, etc...
      • 9130
      • 171 Posts
      I don’t think anything like this exists but you could write a plugin to do it.

      A better approach would be to create a snippet that randomly selects a document from the tree and outputs its ’content’, something like this. Why bother going through the filesystem at all?
        • 25483
        • 741 Posts
        I think you want to random show one of the documents when you load a certain page on the site?

        You could use Ditto to randomly select 1 document from the folder ’Promotions’ and then make a snippet that redirects you to the right page. So you call this snippet from the ditto template and give the id of the document to the snippet so that it can do it’s work.
          with regards,

          Ronald Lokers
          'Front-end developer' @ h2o Media

          • 6561
          • 139 Posts
          Quote from: MediaGuy at Apr 02, 2009, 11:50 AM

          I think you want to random show one of the documents when you load a certain page on the site?

          You could use Ditto to randomly select 1 document from the folder ’Promotions’ and then make a snippet that redirects you to the right page. So you call this snippet from the ditto template and give the id of the document to the snippet so that it can do it’s work.

          Well, I want to output random content, but be able to put any kind of html code in it (I guess this is possible by leaving template field blank?). And to have an easy way for editors to put their own stuff in it.
            • 25483
            • 741 Posts
            Then you could use ditto and use a black document template, but your content editors have to past the complete template they want into the content area.
              with regards,

              Ronald Lokers
              'Front-end developer' @ h2o Media

              • 9130
              • 171 Posts
              Quote from: MediaGuy at Apr 02, 2009, 11:50 AM

              I think you want to random show one of the documents when you load a certain page on the site?

              You could use Ditto to randomly select 1 document from the folder ’Promotions’ and then make a snippet that redirects you to the right page. So you call this snippet from the ditto template and give the id of the document to the snippet so that it can do it’s work.
              I don’t think this meets the requirements. If I understand correctly the random content should only be part of the page (like a text advertisement in the sidebar for example), what you suggested will replace the entire page with a random one.
                • 6561
                • 139 Posts
                Quote from: etal at Apr 02, 2009, 12:44 PM

                Quote from: MediaGuy at Apr 02, 2009, 11:50 AM

                I think you want to random show one of the documents when you load a certain page on the site?

                You could use Ditto to randomly select 1 document from the folder ’Promotions’ and then make a snippet that redirects you to the right page. So you call this snippet from the ditto template and give the id of the document to the snippet so that it can do it’s work.
                I don’t think this meets the requirements. If I understand correctly the random content should only be part of the page (like a text advertisement in the sidebar for example), what you suggested will replace the entire page with a random one.

                Yes, that’s right. It could be a banner, or a text with a picture, or a quote, or ... in this particular case, it’s for a product showcase where I want to randomly showcase one of the products (being a div with unique id and with a picture and some text inside it, plus a link).
                  • 25483
                  • 741 Posts
                  Then you could use Ditto and some template variables to define the image and the link. Then use the content tag and the template variable tags in the Ditto template to show them smiley

                  With the magic of javascript you can even create a carousel that makes a slideshow of multiple documents.
                    with regards,

                    Ronald Lokers
                    'Front-end developer' @ h2o Media

                    • 7231
                    • 4,205 Posts
                    Ditto can do this easily. Just define the tpl to extract the image + text fro the document in question. Then use ditto’s randomize option and set the display to 1 and place the Ditto call where you want the banner to show. That should do what you are trying to accomplish.
                      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                      Something is happening here, but you don't know what it is.
                      Do you, Mr. Jones? - [bob dylan]
                      • 6561
                      • 139 Posts
                      Okay, thanks a lot!

                      Edit: got it, hm that was easier than I thought it would be.

                      Quote from: dev_cw at Apr 02, 2009, 12:56 PM

                      Ditto can do this easily. Just define the tpl to extract the image + text fro the document in question. Then use ditto’s randomize option and set the display to 1 and place the Ditto call where you want the banner to show. That should do what you are trying to accomplish.