Constructing a custom files display
I've been working on this for a couple days now and I feel like I have a pretty good understanding on how the arrays work. What I'm running into is how to get all the information from the array that I need to build the output.
I'm using a file field, Multiple Selection, Enable as Image field and Create Link as file download/Lightbox.
What I'm wanting to do is create a custom output that needs information from both the [files] array and [meta] array. I'm incorporating a jQuery module that needs the HTML formatted differently that what is displayed by the ['value'] output.
If I do the following:
Code:
<?php foreach ($entry['data']['files_field']['files'] as $value): ?>[*]<?php echo $value;?>
<?php endforeach; ?>
I get a listing of the file urls just like I should. Now, since the [meta] array is not contained in the files array, how can I pair the information in the second [meta] array with the information in the first [files] array?
So, in other words, I need the thumbnail image url and size information in the same line output with the file url so I can construct the HTML output. I can do one or the other, but not both at the same time.
A simpler answer might be found in how the output is done by default. If I had that, then I think I could just modify that to suit my needs.. unfortunately, I don't know where that is.
Thank you in advance for your help.
Re: Constructing a custom files display
Hi harley77
I could have helped you if you had posted the template vars :)
Could you do that for me please? :)
Code:
<?php $this->showTemplateVars(); ?>
Re: Constructing a custom files display
Hi, as requested
Code:
[product_gallery] => Array ( [label] => Product Gallery [type] => file [raw] => a:4:{i:0;s:42:"resources/products/web/pkt/pktd1_eh_lg.jpg";i:1;s:43:"resources/products/web/pkt/pktproear013.jpg";i:2;s:37:"resources/products/web/pkt/pkt_c1.jpg";i:3;s:37:"resources/products/web/pkt/pkt_d1.jpg";} [value] => Pktd1 eh lgPktproear013Pkt c1Pkt d1 [files] => Array ( [0] => resources/products/web/pkt/pktd1_eh_lg.jpg [1] => resources/products/web/pkt/pktproear013.jpg [2] => resources/products/web/pkt/pkt_c1.jpg [3] => resources/products/web/pkt/pkt_d1.jpg ) [meta] => Array ( [0] => Array ( [src] => system/html/pktd1_eh_lg-760287dc.jpg [alt] => Pktd1 eh lg [lb] => lbcatalogreader0 [w] => 120 [h] => 69 [wh] => width="120" height="69" [caption] => [metafile] => ) [1] => Array ( [src] => system/html/pktproear013-e84d7f80.jpg [alt] => Pktproear013 [lb] => lbcatalogreader0 [w] => 120 [h] => 90 [wh] => width="120" height="90" [caption] => [metafile] => ) [2] => Array ( [src] => system/html/pkt_c1-3ac82596.jpg [alt] => Pkt c1 [lb] => lbcatalogreader0 [w] => 120 [h] => 98 [wh] => width="120" height="98" [caption] => [metafile] => ) [3] => Array ( [src] => system/html/pkt_d1-b3af6479.jpg [alt] => Pkt d1 [lb] => lbcatalogreader0 [w] => 120 [h] => 98 [wh] => width="120" height="98" [caption] => [metafile] => ) ) )
This is just the readout for the particular field in question (didn't think you would want the whole page, that one is quite long).
Re: Constructing a custom files display
Code:
<?php foreach ($entry['data']['files']['meta'] as $key => $value): ?>
// you are now looping through the meta array and every $key is the same $key as in the files array.
// so you can simply replace that one:
File url: <?php echo $entry['data']['files'][$k]; ?>
Width and height: <?php echo $value['wh']; ?>
<?php endforeach; ?>
This will output all three url's together with the corresponding width and height :)
Re: Constructing a custom files display
Looking at that and experimenting with it, it seems to go back to my original issue. The meta array itself doesn't contain the file url link, just the url to the resized pic.
so, for example, I would want the following information retrived in each loop.
- The Main File url. (ex. resources/products/web/pkt/pktd1_eh_lg.jpg)
- The Thumbnail url (ex. system/html/pktd1_eh_lg-760287dc.jpg)
- width/height stuff.
If I do a foreach for the meta array, the Main file url wouldn't be available since it isn't a part of that array, correct? I'll admit, my php is very... elementary so I'm probably just missing something here.
At anyrate, thank you for your help.
Re: Constructing a custom files display
NM, I did some more testing with what you wrote and it seemed to finally click.
The $Key was the missing element I was looking for. THANK YOU, you have helped me immensely. I owe you a beverage of your liking.
Re: Constructing a custom files display
Just for the benefit of anyone else that may have the same question.
It looks like this when done.
Code:
<?php foreach ($entry['data']['product_gallery']['meta'] as $key => $value): ?>
<ul>[*]
<?php echo $entry['data']['product_gallery']['files'][$key];?>
// The Main URL link
<?php echo $entry['data']['product_gallery']['meta'][$key]['src'];?>
// The path to the thumbnail pic
<?php echo $entry['data']['product_gallery']['meta'][$key]['w'];?>
// width
<?php echo $entry['data']['product_gallery']['meta'][$key]['h'];?>
//height
[/list]
<?php endforeach; ?>
Now, this layout is not the final, it's just a demonstration of all the information being available in each loop through the array. My next step is to insert this into the appropriate HTML so that it will output in the format I need.
Re: Constructing a custom files display
Code:
<?php echo $entry['data']['product_gallery']['meta'][$key]['src'];?>
// The path to the thumbnail pic
<?php echo $entry['data']['product_gallery']['meta'][$key]['w'];?>
// width
<?php echo $entry['data']['product_gallery']['meta'][$key]['h'];?>
//height
is actually to much time spent on typing ;)
Code:
<?php echo $value['src'];?>
// The path to the thumbnail pic
<?php echo $value['w'];?>
// width
<?php echo $value['h'];?>
//height