eZ Community » Forums » Setup & design » Direct link to a file on image

Direct link to a file on image

Direct link to a file on image

Tuesday 15 December 2009 4:10:54 pm - 9 replies


I would like to change access to pdf on my site (stored in Media library > Files > ...) because first I think it's more user-friendly to have direct access to the file, avoiding intermediary page, and second, I would not like user to see Media library folder structure. It's OK for embeded files, thanks to all posts on this subject on this forum, and for a simple text link, many thanks to http://pwet.fr/blog/creating_a_li...ile_with_online_editor_in_ez_publish

BUT I didn't succeed to have a direct link on an image, let's say an image like a banner where you click on you directely download the file without viewing the node. Could anyone help ? Thanks.

Modified on Tuesday 15 December 2009 4:14:39 pm by Catherine Mollet

Wednesday 23 December 2009 7:52:57 pm

Hi Catherine,

It should not be too dificult to add a hyperlink on an image, or banner. As long as it is an image which is placed in for example a folder summary, description or body of an article, you can use the "Insert/edit link" button on the WYSIWYG editor to apply a hyperlink on the image/banner.

So you add the image first, with the "Insert/edit image" button. You then select that image and use the "Insert/edit link" button and once the "New <link> tag" popup appears make sure to select Http: for the Href option and enter your url you want to link the image to. This can of course be a file like a pdf document.

Hope this helps, Regards Robin

Monday 04 January 2010 12:21:17 pm

Hi Robin,

Of course, it's not difficult to add a link on an image. But what I want to do is to insert a direct link to the pdf document itself, stored in Media/Files. Such a link to an object opens a new page with the description of the object and a link to the object itself (ie a fullview page). To avoid it, because I think it's not very user-friendly to have to click twice to download a document, and because I wouldn't like users to see in the pathway, for example, that the pdf is within the folder Media/Files/Myfoldername/Nameofthenodeofmydocument. That's why I first overrided file.tpl in embeded-inline folder with

<a href={concat("content/download/", $file.contentobject_id, "/",
$file.id, "/file/",

Then, I used the solution provided on the article "Creating a link to download a file with Online Editor in eZ Publish" on pwet blog (link above, in the first post). Works fine for text links, but not if the link is a link on an image.

Your solution to link with Http: on Href option can not be used because uploaded files are renamed (ezbinaryfile) e.g /var/ezwebin_site/storage/original/application/182daee67677dfc4b6faa0958751d648.pdf. Of course, I could look for actual address of each pdf withwith a ftp client, but then what would be advantage to use a CMS blunk.gif Emoticon ?

I hope my question is clearer now.

Monday 04 January 2010 8:10:33 pm

Hi Catherine,

That indeed makes your question more clear, I'll have a look around and see if I can give you a better more to the point answer.

Regards Robin

Monday 04 January 2010 9:37:18 pm

Hi Catherine,

Would the following work? http://share.ez.no/forums/setup-design/linking-to-a-file-for-download

I tried setting it up, but can't get it to work yet, bit of a noob on overrides still. Let me know if you get this to work, it would make a nice short How-To article for the community site.

Regards Robin

p.s. found another one, same idea, hopefully this helps; http://share.ez.no/forums/setup-design/linking-directly-to-a-file

Modified on Monday 04 January 2010 9:42:58 pm by Robin Muilwijk

Tuesday 05 January 2010 12:05:12 pm

Thanks Robin for spending time on my question. If our paths cross at a eZ Day or a J! Day (as it seems that you're involved in it too), I'll buy you a beer, promise !

Solutions you pointed at are the ones I'm already using, and it works fine for direct downloads while inserting objects.
To create a direct download link on a free text, I've created a [link] class with override of content/datatype/view/ezxmltags/link.tpl. This "Download" new class works fine with text, but not with images.

Problem is that, for image, link is defined in embed/image.tpl with href=$link_parameters.href|ezurl. I guess that I have to override embed/image.tpl with something like image_direct_download.tpl, but I don't know how to manage the code inside. Still quite a newbee with eZ... Keep trying, but if you find something first, you're welcome !

Tuesday 05 January 2010 1:03:25 pm

Yessss ! I found it. Thanks for inspiration, Robin.

For whose interested in, I adapted http://pwet.fr/blog/creating_a_li...ile_with_online_editor_in_ez_publish with image.tpl. Then, I didn't have to create a image_direct_download.tpl, only override embed/image.tpl with :

{def $n='' $attribute='' $url=false() $protocols=array('http', 'file', 'ftp', 'mailto', 'https')}
<div class="content-view-embed">
<div class="class-image">
    <div class="attribute-image">
    {if is_set( $link_parameters.href )}
    {if $protocols|contains( $link_parameters.href|explode(':')|extract_left(1) )not()}
    {set $n=fetch(content, node, hash(node_path, $link_parameters.href))}
    {if and($n, $n.object.class_identifier|eq('file'))}
    {set $attribute=$n.data_map.file}
    {set $url=concat( '/content/download/', $attribute.contentobject_id, '/', $attribute.id,'/version/', $attribute.version , '/file/', $attribute.content.original_filename|urlencode )}
    {if $url|not()}
    {set $url=$link_parameters.href}
    {attribute_view_gui attribute=$object.data_map.image image_class=$object_parameters.size href=$url|ezurl target=$link_parameters.target border_size=first_set( $object_parameters.border_size, '' ) border_color=first_set( $object_parameters.border_color, '' ) border_style=first_set( $object_parameters.border_style, '' ) margin_size=first_set( $object_parameters.margin_size, '' )}
    {undef $n $attribute $url $protocols}
    {attribute_view_gui attribute=$object.data_map.image image_class=$object_parameters.size border_size=first_set( $object_parameters.border_size, '' ) border_color=first_set( $object_parameters.border_color, '' ) border_style=first_set( $object_parameters.border_style, '' ) margin_size=first_set( $object_parameters.margin_size, '' )}

Step by step, seems I'm getting used with eZ template laguage !

Tuesday 05 January 2010 1:19:36 pm


Glad to see you got this fixed. Sometimes bouncing ideas around helps to get to the finish line happy.gif Emoticon

I'll see if I can convert this information in a step-by-step guide, make it available as a how-to/article for other community members. Thanks for the feedback on how you got it to work.

Regards Robin

p.s. I'll hold you to that beer if we ever meet during a community day, always nice to share experiences

Tuesday 05 April 2011 3:45:18 am

Hi Catherine,

I know it was a long time ago, but I just wanted to say thanks for your solution which helped me in a similar situation.

What I wanted to was to be able to use the normal 'insert link' dialogue in ezoe to create a direct link to images *and* files, in the same way you would for linking to another content object.

In my case, I simply overrided link.tpl with the following code. If the content class of the linked-object is 'image' or 'file', a link to its loction in the var dir is created. Otherwise, links stay the same.

    $dl_protocols=array('http', 'file', 'ftp', 'mailto', 'https')
{if is_set( $href )}
    {if $dl_protocols|contains( $href|explode(':')|extract_left(1) )not()}
        {set $dl_n=fetch(content, node, hash(node_path, $href))}
        {if $dl_n}
            {if or($dl_n.object.class_identifier|eq('image'),$dl_n.object.class_identifier|eq('file'))}
                {if $dl_n.object.class_identifier|eq('image')}
                    {set $dl_attribute=$dl_n.data_map.image}
                    {set $dl_url=concat('/',$dl_attribute.content.original.url)}
                    {set $dl_attribute=$dl_n.data_map.file}
                    {set $dl_url=concat( '/content/download/',  $dl_attribute.contentobject_id, '/',  $dl_attribute.id,'/version/',  $dl_attribute.version , '/file/',  $dl_attribute.content.original_filename|urlencode )}
<a href={if eq($dl_url|count_chars(),0)|not()}{$dl_url}{else}{$href|ezurl()}{/if} {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>
{undef $dl_n $dl_attribute $dl_url $dl_protocols}

Tuesday 01 October 2013 12:27:05 pm

Hi Russel,


Are you talking about extension/ezoe/design/standard/templates/ezoe/customattributes/link.tpl ?

Could you please give more details, I'm a bit lost.

Thanks a lot.

Modified on Tuesday 01 October 2013 12:37:01 pm by fod ger


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

36 542 Users on board!

Forums menu

Proudly Developed with from