Problem: How to display in a template, the information about a file (name, date, etc.).

Author Message

carre philippe

Wednesday 15 September 2010 12:55:19 am

Hello
New to EZ Publish, I submit my problem.
In a template (.TPL) I want to display all the information (ie: name, date, size, etc) about a file located on the server side.
If anyone can help me it will be welcome.
Thank you all.

Romeo Antony

Wednesday 15 September 2010 1:57:38 am

Hi Carre,

welcome to ezcommunity.

First you should read the basics

http://ez.no/doc/ez_publish/technical_manual/4_x/concepts_and_basics

http://ez.no/doc/ez_publish/technical_manual/4_x/concepts_and_basics/content_management

If you want ti display attributes like name etc.

you should fetch it like

{$node.data_map.name}

carre philippe

Thursday 16 September 2010 12:40:48 am

Thank you Romeo
but my problem remains unsolved.
In PHP, with the function "fopen", we know the system date to a file,
but how in a template?
That is the question ...
philippe Carré

Romeo Antony

Thursday 16 September 2010 3:52:56 am

Ok .

If you want to show the file name, file size , date.

Here is the way.

First you find out ezbinaryfle.tpl which is located at content/datatype/view/ezbinaryfile.tpl

this is the template that is used when u use attribute_view_gui for ezbinaryfile.

So what you have to do is in your template file

you have to put

{$node.object.published|l10n(shortdatetime)} // this is to show the date when the file published

{attribute_view_gui attribute=$node.data_map.file icon_title=$node.name} // to show file name and size

next move on to see how this attribute_view_gui attribute working to show file name and size

for that you need to override the content/datatype/view/ezbinaryfile.tpl(you should read override mechanism of ez http://ez.no/doc/ez_publish/techn...mplates/the_template_override_system)

Here is the code

[my_fle_info] // block name in your site access override file
Source=content/datatype/view/ezbinaryfile.tpl // source file which is the deafult file when you

use attribute_gui for file type
MatchFile=content/datatype/view/my_file.tpl // your created override template for attribute_gui for file type

Subdir=templates

Match[class_identifier]=file // override condition for class my_file.tpl instead of ezbinary.tpl

mean whenever you use attribute_gui for ,class type file , it will take my_file.tpl .

so create my_file.tpl and put it in your curent design override folder like this // read http://ez.no/doc/ez_publish/techn...d_basics/designs/design_combinations

current design/override/content/datatype/view/my_file.tpl

Now create the code for my_file.tpl

Like this

{$attribute.content.original_filename|wash( xhtml )} // to show file name

{$attribute.content.filesize|si( byte )} // show file size

Try this link for better understanding

http://share.ez.no/forums/setup-design/override-templates-used-by-attribute_view_gui#comment26315

Yes you are done.

Regards

Romeo.

Kévin S.

Monday 20 September 2010 3:06:35 am

Hello Philippe !

One thing that can be tricky is that your file must be saved in eZ Publish database if you want to access it easily from a template. You can add it in the "media" sub-tree to do so.

Then, you access it in your template using a fetch, for example. With the function "attribute('show', 1)" you can browse the file's metadata and content. Then, if you want to show it a specific way, you can use a template as Romeo described it.

___

Kévin

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