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.

eZ debug

Timing: Jan 18 2025 05:10:24
Script start
Timing: Jan 18 2025 05:10:24
Module start 'layout'
Timing: Jan 18 2025 05:10:24
Module start 'content'
Timing: Jan 18 2025 05:10:25
Module end 'content'
Timing: Jan 18 2025 05:10:25
Script end

Main resources:

Total runtime0.6507 sec
Peak memory usage4,096.0000 KB
Database Queries66

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0068 588.4063152.6875
Module start 'layout' 0.00680.0038 741.093839.5234
Module start 'content' 0.01060.6387 780.6172570.3984
Module end 'content' 0.64930.0014 1,351.015616.0625
Script end 0.6507  1,367.0781 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.5324160.0002
Check MTime0.00140.2167160.0001
Mysql Total
Database connection0.00190.287510.0019
Mysqli_queries0.579889.0944660.0088
Looping result0.00060.0893640.0000
Template Total0.615794.620.3079
Template load0.00210.315520.0010
Template processing0.613694.302920.3068
Template load and register function0.00030.050710.0003
states
state_id_array0.00140.220110.0014
state_identifier_array0.00090.133620.0004
Override
Cache load0.00190.2892650.0000
Sytem overhead
Fetch class attribute can translate value0.00080.119430.0003
Fetch class attribute name0.00200.312660.0003
XML
Image XML parsing0.00060.095730.0002
class_abstraction
Instantiating content class attribute0.00000.002870.0000
General
dbfile0.00080.1217160.0000
String conversion0.00000.001440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 24
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs