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

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

eZ debug

Timing: Jan 18 2025 02:53:25
Script start
Timing: Jan 18 2025 02:53:25
Module start 'content'
Timing: Jan 18 2025 02:53:26
Module end 'content'
Timing: Jan 18 2025 02:53:26
Script end

Main resources:

Total runtime0.8370 sec
Peak memory usage4,096.0000 KB
Database Queries203

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0352 588.0938180.7813
Module start 'content' 0.03520.7007 768.8750575.5234
Module end 'content' 0.73590.1010 1,344.3984337.3359
Script end 0.8369  1,681.7344 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.4592210.0002
Check MTime0.00140.1672210.0001
Mysql Total
Database connection0.00080.101610.0008
Mysqli_queries0.751589.78622030.0037
Looping result0.00160.19312010.0000
Template Total0.779593.120.3898
Template load0.00200.239120.0010
Template processing0.777592.897020.3888
Template load and register function0.00010.013510.0001
states
state_id_array0.00080.098410.0008
state_identifier_array0.00070.080520.0003
Override
Cache load0.00180.2097650.0000
Sytem overhead
Fetch class attribute can translate value0.00110.127240.0003
Fetch class attribute name0.00080.097560.0001
XML
Image XML parsing0.00640.768940.0016
class_abstraction
Instantiating content class attribute0.00000.002070.0000
General
dbfile0.01091.3012270.0004
String conversion0.00000.004230.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 24
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs