Create a direct link to a binary file

Author Message

Nicolas Heiringhoff

Wednesday 28 July 2004 3:17:39 am

Hello erveryone,

we have some problems with creating a direct link to a binary file.
The PDF-files we want to offer for download a stored in a certain folder with the node id 296.
From an override-template of another folder in the tree-hierarchy we can grab the content of node 296 with the following code


{* Fetch everything that is under node #296 (children, grand-children, etc.) *}
{let nodes=fetch( 'content', 'tree', hash( 'parent_node_id', 296 ) ) }

{* Loop through the nodes and display their names. *}
{section loop=$nodes}

<br />
    <a href={concat("/content/view/full/",$:item.node_id)|ezurl}>{$:item.data_map.titel.data_text}</a>
    
    <br />
    {$:item.data_map.beschreibung.data_text}
    
    <br />
    
    {$:item.data_map.binaer.data_???}
    
    <br /> 

We can display the attributes title (identifier="titel") and description (identifier="beschreibung") but we can not display the actual file directly (identifier="binaer"), because we do not know the data_map. For the title and the description it is "data_text". We also used data_int before, to display numbers. Which data_map can we use to display the file?

When you click on the link that we generated with the code above, the file plus the filsize is displayed directly by the ezbinaryfile.tpl, that is used there. We want exactly that, but copying the ezbinaryfile.tpl in our override template does not work.

http://www.heiringhoff.de

Roy Bøhmer

Monday 02 August 2004 11:11:53 am

Sorry for the late answer. Hope you already have figured something out.
I've used this code whith success. Hope it helps.

<a href={concat("content/download/",
			$object.id,
			"/",
			$object.data_map.file.id,
			"/file/",
			$object.data_map.file.content.original_filename)|ezurl}>
			{$object.name|wash}</a>

You should replace <i>$object</i> with <i>$:item.object</i> and ensure that the attributename for the binary file in the class is file. If not, replace <i>file</i> with the attributename.

Roy

Nicolas Heiringhoff

Tuesday 03 August 2004 4:00:30 am

Hello Roy,

your code works perfectly fine!

Thank you very much!

Nicolas

http://www.heiringhoff.de

willy jansen

Monday 15 November 2004 9:39:12 am

Congratulations! Would you mind explaining how you solved this and what code you used. For at least one person (me) is looking for a similar solution, but the information above is not sufficient for me.

Nicolas Heiringhoff

Tuesday 16 November 2004 12:17:02 am

Hello Willy,

We put the files (pdfs in our case) in one folder (node id 296).
With the following code we can display the pdfs with a direct download link in a template.


{* Fetch everything that is under node #296 (children, grand-children, etc.) *}
{let nodes=fetch( 'content', 'tree', hash( 'parent_node_id', 296 ) ) }

{* Loop through the nodes and display their names. *}
{section loop=$nodes}


<br />

<span class="fett">{$:item.data_map.titel.data_text}</span>

<br />

{$:item.data_map.beschreibung.data_text}

<br />

<img src={"pdf_mini_icon.png"|ezimage}&nbsp; &nbsp; 

<a href={concat("content/download/",
                        $:item.object.id,
                        "/",
                        $:item.object.data_map.file.id,
                        "/file/",
                        $:item.object.data_map.file.content.original_filename)|ezurl}>
                        {$:item.object.name|wash}</a>

    <br />   
{/section}



{/let}

Regards,
Nico

http://www.heiringhoff.de

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.