output-big.png

Output content to a file

By Ladoo posted on 17 Nov 2011

As well as HTML and text, Matrix can be configured to directly output XML, iCal, RTF and even Word and Excel documents, so that users can directly download and work with these files. Some examples of why you might want to output to a file format include:

  • to allow staff to download an XML file so it can be imported into another system;
  • to generate a Word Document, which needs to filled in, signed and faxed;
  • to create an Excel Document, which can then be used to generate a graph;
  • to create a calendar of events, which can be subscribed to.
The technique for outputting to each format is essentially the same: we trick the browser into thinking it's downloading a particular type of file instead of a regular HTML page. To do this, we need to create a special design that can be applied to an asset, or a group of assets in Matrix. For each file type, we'll specifically look at the code that needs to be included in the Design file, but generally, the code will be as follows:
<MySource_PRINT id_name="__global__" var="content_type" content_type="application/rtf" />
<MySource_AREA id_name="page_body" design_area="body" />
<MySource_PRINT id_name="__global__" var="content_attachment" extension="rtf" />

For each file type, we need to substitute X for the file type, and Y for the file extension. It's also important that any asset these Designs are applied to has all its DIVs set with a Presentation and Content Type of "Raw HTML", otherwise Matrix will insert <div> tags where we don't want them.

Now let's look at how to configure the Design for each type of file.

RTF documents

 

RTF documents are more widely supported than Word Documents, allow for the rich formatting for text, and don’t contain Macros/potential viruses. To output the content of a page as a RTF document, create and apply a Design as follows:

<MySource_PRINT id_name="__global__" var="content_type" content_type="application/rtf" />
<MySource_AREA id_name="page_body" design_area="body" />
<MySource_PRINT id_name="__global__" var="content_attachment" extension="rtf" />
Next, create and save an RTF document in Microsoft Word, or any of the many other text editing applications that can save as RTF.

Finally, open the document in a text editor like Notepad, and paste the entire raw text into the Page Contents DIV. Now, if you preview the asset that has the RTF Design applied to it, your browser should prompt you to save the RTF file.

Word documents

Pre-2007 versions of Microsoft Word used a proprietary file format which was very difficult for other applications to work with. Office 2007 (and older versions of Word using a compatibility update) uses an XML format: .docx instead of the old .doc. Although this is comprised of XML, its file format is compressed and is therefore still difficult to use within Matrix. A nice way around this problem is to use plain old HTML, as this is something Word does understand.

To output the content of a page as a Word document, create and apply a Design as follows:

<MySource_PRINT id_name="__global__" var="content_type" content_type="application/msword" />
<MySource_PRINT id_name="__global__" var="content_attachment" extension="doc" />
<html>
  <body>
    <MySource_AREA id_name="page_body" design_area="body" />
  </body>
</html> 

If you now preview an asset with this Design applied, your browser or operating system should attempt to open the file in Microsoft Word. From there, you save the Document into a Word format and switch the View back to "Page Layout" (from "Online Layout").

Excel documents

To output the content of a page as an Excel document, create and apply a Design as follows:

<MySource_PRINT id_name="__global__" var="content_type" 
content_type="application/msexcel" />
<MySource_PRINT id_name="__global__" var="content_attachment" extension="xls" />
<MySource_AREA id_name="page_body" design_area="body" /> 

Once the Design is applied, create a simple spreadsheet in Microsoft Excel and save the file as an "XML Spreadsheet". Open this saved XML file in a text editor and paste the contents into your page.

If you now preview an asset with this Design applied, your browser or operating system should attempt to open the file in Microsoft Excel.

Asset Listing iCal

 

In the previous examples, the data we inserted into our files was static. Let’s extend these examples by inserting dynamic data via an Asset Listing, and creating an iCal formatted calendar. This will allow users to automatically import this event information into their calendar applications, rather than having to visit your site for updates.

First, let's create some dummy Single Calendar Event assets which we can then list. As an example, create:

  • A Single Calendar Event asset named "Wedding" with a description of "Someone's wedding". Set a start and end date/time.
  • A Single Calendar Event asset named "Birthday" with a description of "Someone's birthday". Set a different start and end date/time than the wedding event asset.

Next, create an Asset Listing named "iCal listing", and on the Details screen set Asset Types to List to "Single Calendar Event" and Root Nodes to the Root Node of your site. Preview the Asset Listing, and you should see the two linked Single Calendar Events listed.

Then, as in the previous examples, it's important this Asset Listing has all its DIVs set to have a Presentation and Content Type of “Raw HTML”, otherwise Matrix will insert <div> tags where we don’t want them.

Then format the Asset Listing Page Contents as:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//iCal title//NONSGML v1.0//EN
%asset_listing%
END:VCALENDAR
and format the Asset Listing Type Format (ensure there is a line break after this code) as:
BEGIN:VEVENT
DTSTART:%event_start_time_ical%
DTEND:%event_end_time_ical%
SUMMARY:%asset_attribute_description%
END:VEVENT
Next, create a Design and apply it to the Asset Listing:
<MySource_PRINT id_name="__global__" var="content_type" content_type="text/calendar" />
<MySource_area id_name="body" design_area="body"/>

Finally, copy the URL of the Asset Listing from the Web Paths screen, and subscribe to the URL via a calendar application like Microsoft Outlook, Apple iCal or Google Calendar. You should now see the two events we created in your calendar, with dates, times and descriptions.

This is a great way to share your organisation’s events externally or within your organisation, because it allows users to draw this information into their calendar applications, rather than having to visit your site for updates.


Comments


  1. Avatar
    07 Jun 2013 12:57pm Michael
    Fantastic, thanks!
  2. Avatar
    12 Jul 2013 2:26pm Myra Domigan
    Works fine in Iphone and Ipad but has errors  in import to Google calendar, I keep getting. Failed to import events: Unable to process your iCal/CSV file..
    Error at line 6: Unparseable date: &quot;&quot; Any advice.
  3. Avatar
    31 Jul 2013 4:31pm Liam
    Hi Myra, 

    You may need to check to see if your iCal event has a valid end date. It appears that google isnt too keen on allowing these type of events. You can edit your ical in notepad or similar to see if it has anything in the DTEND: attribute. If it doesnt go to your event details screen, grab the locks and tick the runs checkbox and the for radio button and leave minutes blank and save the asset. It should then have a 24 hour run period and will export/import correctly.

    Hope this helps
    Liam
Post a new comment Post a new comment

Build your own search

By Ladoo posted on 20 Oct 2011

You can create your own personal Search Page to assist with locating and editing the content you look after. This can be especially helpful in larger systems where quick search becomes less accurate.

Release notes for Matrix 1.2

By Anton Babushkin posted on 16 Jul 2013

You can create your own personal Search Page to assist with locating and editing the content you look after. This can be especially helpful in larger systems where quick search becomes less accurate.

Dynamic Asset Listings

By Liam Coltman posted on 14 Aug 2010

Learn how to make you asset listings dynamic so they can be reused across multiple pages on your site

Comment all you want

By Liam Coltman posted on 08 Sep 2011

Using a combination of an Asset Builder and an Asset Listing in Mysource Matrix can allow you to create a comment area in your website and can be used for blogs.

Trigger happy images

By Liam Coltman posted on 23 Aug 2010

Triggers are a very powerful feature in MySource Matrix. Learn how to set up a trigger to create image varieties

Pretty as a picture Image Gallery

By Liam Coltman posted on 13 Nov 2010

Image Galleries can help to add a bit of colour to your website. With a little bit of tinkering you can make an image gallery that will rival the Louvre

Search

By Ladoo posted on 23 Feb 2012

Most content management systems only offer basic search functionality, and Matrix is no exception.

News delivered to your doorstep

By Liam Coltman posted on 10 Sep 2010

With users becoming more and more demanding on their news and website updates RSS provides the perfect option to keep readers up to date with what is happening on your site.

Matrix PHP API - Creating Standard Page Assets

By Anton Babushkin posted on 28 Feb 2011

Using the Matrix PHP API can allow you to do more than you previously would have thought possible. This article will teach you how to create Standard Page assets as well as give you some insight into when you could utilize the PHP API in the real world.

Paint Layouts

By Liam Coltman posted on 06 Mar 2010

The best way to think of a Paint Layout is a Design File for your page content.