Entry

Download Content Plugin

by: Derek Jones on: 9/20/2011

We just pushed a new, very simple free plugin to our GitHub accountDownload Content is handy if you are using channels to manage information that you want to have available as file downloads for your visitors.  It’s essentially a very simple way to utilize CodeIgniter’s download helper within an ExpressionEngine template.  It takes arbitrary content, and sends it to the browser with the proper file type headers for download.

For example, we’re using it on our intranet to have downloadable vCards for our staff:

{exp:channel:entries limit="1" require_entry="yes" channel="el_intranet_address_book"}
{exp:download_content filename="{el_contacts_firstname} {title}.vcf"}
BEGIN:VCARD
VERSION:3.0
N:{title};{el_contacts_firstname};;;
FN:{el_contacts_firstname} {title}
ORG:EllisLab\, Inc.;
TITLE:{el_contacts_title}
TEL;TYPE=CELL,VOICE:{el_contacts_cellphone}
TEL;TYPE=HOME,VOICE:{el_contacts_otherphone}
ADR;TYPE=HOME:;;{el_contacts_street_address};{el_contacts_city};{el_contacts_state};{el_contacts_zip};{el_contacts_country}
LABEL;TYPE=Home:{el_contacts_street_address}\n{el_contacts_city}\n{el_contacts_state}\n{el_contacts_zip}\n{el_contacts_country}
EMAIL;TYPE=PREF,INTERNET:{exp:low_replace find="_" replace="."}{url_title}{/exp:low_replace}@ellislab.com
EMAIL;TYPE=HOME,INTERNET:{el_contacts_alt_email}
REV:{gmt_edit_date format="%Y%m%dT%H%i%s%Z"}
END:VCARD
{/exp:download_content}
{/exp:channel:entries}

The filename= parameter sets the stage for what type of file will be downloaded.  In this case, it’s a .vcf file.  The plugin takes the content inside its tag pair, and sends its output straight to the browser as a download with the proper filename.

Simple, but quite useful for outputting dynamic downloadable files via ExpressionEngine.  Download Content, like many of our other free add-ons, is distributed as open source software with the MIT/X license.

.(JavaScript must be enabled to view this email address) or share your feedback on this entry with @ellislab on Twitter.

ExpressionEngine News

#eecms, #events, #releases