Forums / General / Link to PDF file

Link to PDF file

Author Message

srikanth mn

Tuesday 21 July 2009 2:49:13 am

HI, i am new to eZ Publsih....i want to have a link to PDF file. can any one help me how to do it in eZ publish.

For example in HTML we use <a href="xxx.pdf" target="_blank">PDF</a>.

How should i add in eZ publish. This is very urgent can any one help me out.

Thanks
Srikanth

Gaetano Giunta

Tuesday 21 July 2009 5:27:29 am

Where is the pdf you want to put the link to:
- in a 'binary content' attribute of a content object?
- is it the pdf rendering of a content object itself?
- is it stored outside of eZ Publish?

The answer will be different...

Principal Consultant International Business
Member of the Community Project Board

srikanth mn

Tuesday 21 July 2009 6:13:14 am

I have uploaded the pdf file from Media section. I have a text link, when i click this link pdf file should open in new window.

Max Keil

Tuesday 21 July 2009 3:33:50 pm

Hi,

this snippet should help you out:


{* Fetch the node of your PDF file *}
{def $pdfnode = fetch( 'content', 'node', hash( 'node_id', PDFNODEID ) )}

{* Display your uploaded PDF file from the object *}
{attribute_view_gui attribute=$pdfnode.data_map.FILE}

In this case - FILE should be the attribute identifier of your class attribute!
The link should looks like this:

<a href="/content/download/711/3824/version/4/file/sharemagazine_june_2009.pdf">SHARE Magazine</a>

Mit freundlichen Grüßen
Best regards

Max Keil

____________________________________________________________
eZ Publish Gold Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

Gaetano Giunta

Wednesday 22 July 2009 12:47:42 am

If you want to customize the anchor tag, you can use something like this:

<a target="_whatever" href="{$node.data_map.FILE.content.filepath|ezroot()}>dowbload</a>

Take care: the above code puts a direct link to the pdf, so access restrictions will not be checked by eZP.

You can examine the templates design/standard/templates/content/datatype/view/ezbinaryfile.tpl and design/standard/templates/content/datatype/view/ezbinaryfile_direct.tpl for more info

Principal Consultant International Business
Member of the Community Project Board

srikanth mn

Wednesday 22 July 2009 4:44:41 am

still it's not working

my pdf file is in path "var/plain_site/storage/original/application/meeting.pdf" after uploading from Media tab

it's Node ID i.e "meeting.pdf" is "110"

I had written like this

<a target="_blank" href="{$node.data_map.FILE.content.var/plain_site/storage/original/application/meeting.pdf"|ezroot()}>meeting</a>

since i am very new to this can you explain in little brief, how should i specify the url. i should add any other extra line for this...?

kracker (the)

Wednesday 22 July 2009 4:53:42 am

@ srikanth
Your code should match Gaetano's example, Please note you do not need to specify an actual path string this already provided in the 'filepath' variable. Basically just use this syntax. Note your $node name may be different.

<a target="_whatever" href="{$node.data_map.file.content.filepath|ezroot()}>dawn of the load</a>

<i>//kracker</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

srikanth mn

Wednesday 22 July 2009 5:57:33 am

how to find the node name.....can you please provide and example...

Gaetano Giunta

Wednesday 22 July 2009 9:19:23 am

As stated above, if you know the node ID, you can fetch the node object like this:

{def $pdfnode = fetch( 'content', 'node', hash( 'node_id', PDFNODEID ) )}

where you change PDFNODEID with your value.

At this point the $pdfnode variable contains an object, of class ezcontentobjecttreenode.
You should really read up a little bit the doc page here: http://ez.no/doc/ez_publish/technical_manual/4_0/reference/objects/ezcontentobjecttreenode to learn what you can find inside it.

The name is f.e. {$pdfnode.name}, but you should remember to wash it to avoid breaking html, so you output it to html using {$pdfnode.name|wash()}

Principal Consultant International Business
Member of the Community Project Board

Max Keil

Wednesday 22 July 2009 4:49:20 pm

If your NodeID is 110 - your code should looks like this:

{* Fetching the Node with ID 110 *}
{def $pdfnode = fetch( 'content', 'node', hash( 'node_id', 110 ) )}

<a target="_blank" href="{$pdfnode.data_map.file.content.filepath|ezroot()}>{$pdfnode.name|wash()}</a>

<i>Gaetano Giunta: Take care: the above code puts a direct link to the pdf, so access restrictions will not be checked by eZP.</i>

Mit freundlichen Grüßen
Best regards

Max Keil

____________________________________________________________
eZ Publish Gold Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

srikanth mn

Thursday 23 July 2009 3:01:10 am

I tryed the following code's but didn't work, please help

{* Fetching the Node with ID 110 *}

{def $pdfnode = fetch( 'content', 'node', hash( 'node_id', 110 ) )}

<a target="_blank" href="{$pdfnode.data_map.file.content.filepath|ezroot()}>{$pdfnode.name|wash()}</a>

After placing this code i got link with particular file name ex:- "special". this is the file name of node id 110. after i click this link it doesn't open any pdf file. it just link to same page where i am. in my case, i have placed this code in home page. link navigate to home page after clicking through pdf file.

I have tryed with one more type

{* Fetching the Node with ID 110 *}

{def $pdfnode = fetch( 'content', 'node', hash( 'node_id', 110 ) )}
{* Display your uploaded PDF file from the object *}

{attribute_view_gui attribute=$pdfnode.data_map.FILE}
<a href={'content/download/111/510/version/1/file/special.pdf' |ezroot()} class="menu">aaa</a>

-----------------------------------------------------------
Basically i want to open a PDF file in new window as we do in HTML

<a href="special.pdf" target="_blank">special</a>

in what other way i can get the solution for this.

since this is very urgent can any one give me yr phone number or chat id so that i can get the solution more faster

Gaetano Giunta

Thursday 23 July 2009 8:27:54 am

You should learn how to debug your template code:

{* Fetching the Node with ID 110 *}
{def $pdfnode = fetch( 'content', 'node', hash( 'node_id', 110 ) )}
{* examine content of the 'file' attribute *}
{$pdfnode.data_map.file.content|attribute(show)}

There are also some debug helper extensions in projects.ez.no, such as this one: http://projects.ez.no/ezdebug_template_operator

Principal Consultant International Business
Member of the Community Project Board

srikanth mn

Thursday 23 July 2009 8:47:29 am

Gaetano Giunta :- following is the output which i got from your code

Attribute Type Value
contentobject_attribute_id string 510
version string 1
filename string '5af143c02e239694cd37a771265dd005.pdf'
original_filename string 'f1b43bbe062c2885d61666cf692bd401.pdf'
mime_type string 'application/pdf'
download_count string 1
filesize integer 65536
filepath string 'var/plain_site/storage/original/application/5af143c02e239694cd37a771265dd005.pdf'
mime_type_category string 'application'
mime_type_part string 'pdf'

Gaetano Giunta

Thursday 23 July 2009 9:16:06 am

See? the '.filepath' part of the node is ok.

If you examine the html source of your page, you will probably then find out that you have something like this:
<a href=""http://mysite/ezdir/var/storage/etc..."" target="_blank" etc...
(see the double double-quotes in the line above?)

It was a fault on my part, and you should be able to troubleshoot it reading the docs for the ezroot() template operator: http://ez.no/doc/ez_publish/technical_manual/4_0/reference/template_operators/urls/ezroot

the correct version should then be
<a target="_blank" href={$pdfnode.data_map.file.content.filepath|ezroot()}>{$pdfnode.name|wash()}</a>

Principal Consultant International Business
Member of the Community Project Board

Max Keil

Thursday 23 July 2009 12:36:06 pm

Sorry, my fault.

{* Fetching the Node with ID 110 *}

{def $pdfnode = fetch( 'content', 'node', hash( 'node_id', 110 ) )}

<a target="_blank" href="{$pdfnode.data_map.file.content.filepath|ezroot('no')}>{$pdfnode.name|wash()}</a>

I forgot to set no in the ezroot template operator - it prevents the operator to create it's own quotation mark inside the html code.

<a href=""http://www.example.com"" target="_blank">...</a> looks realy strage in html.

Mit freundlichen Grüßen
Best regards

Max Keil

____________________________________________________________
eZ Publish Gold Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

srikanth mn

Friday 24 July 2009 4:56:17 am

it works now....thanks

is there any way we can link from article......?

Max Keil

Monday 27 July 2009 12:24:18 pm

Please refer to your other post: http://ez.no/developer/forum/general/horizontal_rulein_article

Mit freundlichen Grüßen
Best regards

Max Keil

____________________________________________________________
eZ Publish Gold Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh