Share » Forums » General » a direct link to download a file from...

a direct link to download a file from the online editor

a direct link to download a file from the online editor

Tuesday 25 May 2010 3:19:40 am - 2 replies

Author Message

Håkan Bergman

Tuesday 25 May 2010 5:10:49 am

I did this with another approach with an override of link.tpl for content datatype xmltags.

The template check if the link is a file and then prints a direct link to the object, if not, just prints the default link value.

/extension/myextension/design/myextension/templates/content/datatype/view/ezxmltags/link.tpl:

{* Define values we are checking for protocols, content, attributes and URL *}
{def $protocols=array('http', 'file', 'ftp', 'mailto', 'https', 'image')
$mycontent = ""
$attribute = ""
$url = false()
}
{* Fetch content from path *}
{set $mycontent=fetch(content, node, hash(node_path, $href))}
{* Verify the path URL and identify the source *}
{switch match=$href}
{* If the path is a file object, print the direct URL to file for download *}
{case match=$mycontent.object.class_identifier|eq('file'))}
{set $attribute=$mycontent.data_map.file}
{set $url=concat( '/content/download/', $attribute.contentobject_id, '/', $attribute.id,'/version/', $attribute.version , '/file/', $attribute.content.original_filename|urlencode )}
<a href={$url|ezurl} target="_blank">{$content}</a>
{/case}
{* If no match was made, print the default URL link *}
{case}
<a href={$href|ezurl}
{if $id} id="{$id}"{/if}
{if $title} title="{$title}"{/if}
{if $target} target="{$target}"{/if}
{if $classification} class="{$classification|wash}"{/if}
{if and(is_set( $hreflang ), $hreflang)} hreflang="{$hreflang|wash}"{/if}
>
{$content}
</a>
{/case}

{/switch}

Veronique Jamilloux

Tuesday 01 June 2010 1:41:09 am

Hi,

Ok I'm going to try your solution.

Thank you very much

Véronique

URGI - INRA
Webmaster
Route de Saint Cyr
78000 Versailles

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu