We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7231
    • 4,205 Posts
    I am trying add an option to download event information as iCal. I see the iCal format and that is not too hard to build, but when I click on the link it displays the data on screen rather than downloading. How do I make it download and have the .ics extension?
      [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]
      • 1122
      • 209 Posts
      You need to create a kind of download manager and send from within it appropriate headers to browser:
        header('Content-Disposition: attachment; filename=' . $name_for_ical_file);
        header('Content-Type: application/x-download');
        header('Content-Length: ' . $length_of_data_to_be_sent);
        // here send your data;
      

      (And also remember that if this is to take effect you cannot send any data before sending headers.)
        • 7231
        • 4,205 Posts
        Thanks. Now I remember grin

        BTW - you can do this with the page settings tab in the manager by setting the Content Disposition to Attachment rather than inline. (I remembered this when I saw your code for the content disposition).
          [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]
          • 29839 ☆ A M B ☆
          • 66 Posts
          Would love to see a plugin that allows you to put a link on a page with "add to calendar", just like they have on eventbrite...
            • 9102 ☆ A M B ☆
            • 318 Posts
            Would love to see a plugin that allows you to put a link on a page with "add to calendar"
            I'll do that.

            I already have code for the setup dev_cw describes as part of my new Webinex webinar management extra. I submitted it to the repo a couple of days ago, it hasn't been accepted yet. The source is here:

            https://github.com/freejung/Webinex

            An example of the iCal portion is here:

            http://www.dealerwebinars.com/registration-thanks.html?ps=115

            It would be easy enough to separate out the iCal portion as a stand-alone snippet, pack it up with PackMan, and submit it as a separate extra. Give me a day or two to find the time.
              • 9102 ☆ A M B ☆
              • 318 Posts
              OK, I've created an iCal extra for Revo and sumbitted it to the repository. It's called iCalX.

              If you want to use it before it's approved, you can download the transport package here:

              http://www.dealerwebinars.com/assets/files/ical/icalx-1.0.0-beta.transport.zip

              It's just a pair of snippets and a chunk.

              Place the iCalGenerator snippet at the top of your template before any other characters.

              Place the iCalLink snippet inside the href of your ical download link.

              The chunk is a template for a file in iCal format, you can specify a different template chunk if you want to copy and modify it.

              The iCalLink snippet takes various parameters defining the properties of the iCal file, such as summary and start date/time. The parameters are described in the readme.

              You can have multiple iCal links per page. You just have to specify the "instance" parameter as a unique integer for each link.

              It supports passing data via either _SESSION or _GET. Using _SESSION requires cookies, whereas using _GET results in very ugly URLs.
                • 9102 ☆ A M B ☆
                • 318 Posts
                This extra has now been accepted and is available through Package Management, as is my new webinar management extra Webinex.
                  • 36722
                  • 101 Posts
                  I can't get this to work for the life of me.

                  on MODx 2.28 / NGINX

                  First line in template
                  [[!iCalGenerator?&useSession=`1`]]


                  link code
                  	<p><a href="[[!iCalLink?
                                                          &useSession=`1`
                                                          &instance=`1` 
                                                          &dtstart=`[[*mnsea-event-date]]` 
                                                          &dtend=`[*mnsea-event-date-end]]` 
                                                          &description=`[[*pagetitle]]` 
                                                          &summary=`[[*introtext]]`
                                                          &reminder=`1440`
                                                          &filename=`mnsea-event.ics`]]">Add to Calendar</a></p>


                  No matter what option I use, the link snippet gives me the long GET style link
                    Shawn Himmelberger
                    Himmelberger Design
                    https://himmdesign.com/services/website-development/modx"" target="_blank" rel="nofollow"> MODx Web Design | https://himmdesign.com/services/website-development/modx"" target="_blank" rel="nofollow"> MODx Web Development
                    • 9102 ☆ A M B ☆
                    • 318 Posts
                    Hi himmdesign, sorry for not seeing this earlier.

                    I'm not seeing what's wrong here, though. I tried using the same code and it generates the link correctly. The iCalLink snippet is extremely simple and doesn't even check to make sure the session variable is set correctly (it probably should) before generating the URL. Further, it should generate the correct link regardless of the options in the iCalGenerator script.

                    It should create a link like http://www.yoursite.com/page.html?cal=1 with the options you posted.

                    Does the link it generates actually work? What is the URL?