String from yaml for niceSize() required

How would I obtain a string for niceSize from the following content file? Tests return same values for 30 different products. thanks


    Image: basketball/BB-1500-4.jpg
    File1 : 98-0001-08led-bar-bb.pdf    //this is in content/products/manuals 
    File2: basketball/BB-1500-4.pdf

    Image: basketball/BB-1520-4.jpg
    File1: 98-0001-08led-bar-bb.pdf
    File2: /basketball/BB-1520-4.pdf
$productdetails = yaml($page->productdetails())
foreach($productdetails as $product):

if($document = $product['File1']):
<a class="btn-u" href= echo url of product manual ...
if($document = $product['File2']):
<a class="btn-u" href= echo url of product spec ...

Try this:

<?php echo $page->file($document)->niceSize(); ?>

Thanks for the reply. The first value of 205.44kb, is displayed for all 60 values that I loop through. I know the spec sheet and manual values are updating properly through the loop though.

Could you please post the current PHP code of that loop?

<?php $productdetails = yaml($page->productdetails()) ?>
<?php foreach($productdetails as $product): ?>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">
<div class="thumbnails thumbnail-style thumbnail-tl">
<div class="thumbnail-img">
<div class="overflow-hidden">
<img class="img-responsive" src="<?php echo $product['Image']?>" alt="<?php echo $product['AltText'] ?>" />
<div class="caption">
<div class="headline-left margin-bottom-20">
<h4 class="headline-brd">Model: <span class="pull-right"><?php echo $product['Model'] ?></span></h4></div>
<?php if($document = $product['File1']): ?>
    <a class="btn-u" href="<?php echo url($document) ?>">Product Manual</a><?php echo $page->document()->niceSize(); ?>
<?php endif ?>
<?php if($document = $product['File2']): ?>
 <a class="btn-u btn-brd btn-brd-hover btn-u-dark" href="<?php echo url($document) ?>">Spec Sheet</a><?php echo $page->document()->niceSize(); ?>
<?php endif ?>                                            
<?php endforeach ?>

Ok, you use $page->document(), but without a parameter, that method will always fetch the same file (i.e. the first)… I suggested you use this code:

<?php echo $page->file($document)->niceSize(); ?>


<?php echo $page->document($document)->niceSize(); ?>

Tried this but error. Is it because of yaml? Thanks.

I think the path to the file is missing, if the files are in a subdirectory of the current page. Try this then:

<?php echo $page->children()->find('manuals')->document($document)->niceSize(); ?>

But then the url to the file can’t possible be correct, either?

I agree that if the url is correct the call to niceSize should work?
I didn’t use a standard directory setup so I am trying to call a pdf in a upper directory.
The spec file is in content/products/fp/bb/spec.pdf
Both pdfs are found from my txt file yaml array but niceSize still problem. This is result after trying above:

Well, you have to get the correct path to the file, if it is not in a child page, the above code will indeed not work. I think you should save the correct path to the files in your content file.

I guess I should back up. I am getting one file size and that is from the first pdf in the content folder of original txt file when I use my original method. I am accessing the info incorrectly I am sure.
File1: products/manuals/98-0002-08led-bar-bb.pdf
Fiile2: bb/BB-1004.pdf which is 125.7 kb.

I have two issues. One is that the first pdf file size is always displayed in spite of 30 products in loop. The second problem is accessing the folder of manuals in a higher directory.
Any thoughts?

I thought about this again, and it is better, to remove the path from the file field (so just put the filename there) and get the file/file size like this:

<?= page('products/manuals')->document($item->item_image())->niceSize() ?>

Thank you that does work!!