smarty filesize

Get help with installation and running PivotX 2.0.x here. Please do not post Extension or Theme related questions here.

smarty filesize

Postby winters » Sun Mar 27, 2016 4:31 pm

for a download list (made with bonus fields) I would like to use

filesize (with smarty)

does someone no what the correct use is for filesize (or is it not working anyway in pivotx)

I used
[[$entry.extrafields.file|filesize]]

output is nothing

is based it on
http://www.smarty.net/forums/viewtopic. ... 144e45fbb6

thanks and have a nice day!
winters
 
Posts: 82
Joined: Thu Jan 13, 2011 9:09 pm

Re: smarty filesize

Postby Harm10 » Wed Mar 30, 2016 7:46 pm

I do not think this is part of Smarty 2.
Wouldn't it be much simpler to create a small php snippet for it?
That has filesize built in: http://php.net/manual/en/function.filesize.php
Quality is in the detail of things............

Want to change or update your PivotX site? Mail or PM me!
I can also convert your site to a Wordpress site!
Harm10
Developer
 
Posts: 2010
Joined: Wed Jun 17, 2009 9:37 am
Location: Somewhere in The Netherlands (aka Holland)

Re: smarty filesize

Postby winters » Thu Mar 31, 2016 3:26 pm

Code: Select all
     [[ php ]]
function file_size($url){
    $size = filesize($url);
    if($size >= 1073741824){
        $fileSize = round($size/1024/1024/1024,1) . 'GB';
    }elseif($size >= 1048576){
        $fileSize = round($size/1024/1024,1) . 'MB';
    }elseif($size >= 1024){
        $fileSize = round($size/1024,1) . 'KB';
    }else{
        $fileSize = $size . ' bytes';
    }
    return $fileSize;
}
echo file_size('images/$entry.extrafields.file');
                                       
                                        [[/php]]


it works with a file in php but not in pivotx is it easy for you to see what i do wrong?
(and yes the extrafields.file is filled and allow_php_in_templates to 1 )

thanks!
winters
 
Posts: 82
Joined: Thu Jan 13, 2011 9:09 pm

Re: smarty filesize

Postby Harm10 » Thu Mar 31, 2016 4:00 pm

When running php within your site you need to be aware of the cwd (current work directory).
So use getcwd(), assign that to a var and echo that.
Relative folder annotations are added to the cwd setting by php.
You can also use some of the the available paths variables from PivotX to create a full url to the image.
E.g. home_path.
Quality is in the detail of things............

Want to change or update your PivotX site? Mail or PM me!
I can also convert your site to a Wordpress site!
Harm10
Developer
 
Posts: 2010
Joined: Wed Jun 17, 2009 9:37 am
Location: Somewhere in The Netherlands (aka Holland)

Re: smarty filesize

Postby winters » Thu Mar 31, 2016 4:21 pm

thanks harm I got the path sorted out!

if I test echo $entry.extrafields.file; it is empty
and if I use outside the [[php]] tags [[$entry.extrafields.file]] it shows me the content of the field

do you happen to know how to use extrafields in [[php]] tags ?

thanks again!
winters
 
Posts: 82
Joined: Thu Jan 13, 2011 9:09 pm

Re: smarty filesize

Postby Harm10 » Thu Mar 31, 2016 6:42 pm

Code: Select all
[[php]]
$vars = $this->get_template_vars();
$myvar = $vars['entry']['extrafields']['file'];
[[/php]]
Should work.
Quality is in the detail of things............

Want to change or update your PivotX site? Mail or PM me!
I can also convert your site to a Wordpress site!
Harm10
Developer
 
Posts: 2010
Joined: Wed Jun 17, 2009 9:37 am
Location: Somewhere in The Netherlands (aka Holland)

Re: smarty filesize

Postby winters » Thu Mar 31, 2016 7:19 pm

as always: thanks for your help!
winters
 
Posts: 82
Joined: Thu Jan 13, 2011 9:09 pm


Return to 2.x Support Forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron