So I downloaded and really enjoyed getting started with Kirby http://www.getkirby.com
For those not familiar it is a file based cms.
As standard you can drop a bunch of images in a directory e.g. site/number1 and it will make a gallery for you on a page called site.com/number1. If one of your images is called example.jpg you can make a file called example.txt and put inside information relating to the image such as title, date etc.
I wasn't totally happy with the idea of having a text file for each individual image and having the images scattered around the server in the page folders.
First of all I put a large collection of images in assets and added a variable to the page so I just need to add the image ref e.g. k-45 to a list in the page.txt e.g.
----
Imagelist: a-04, a-08, h-16, i-35
I then added the following snippet:
<ul class="gallery">
<?php $imagelist= $page->imagelist();
if ($imagelist != ''){
$imagelistitem= explode(", ", $imagelist);
foreach ($imagelistitem as $image): ?>
<li><img src="<?php echo url('assets/artistswork/450/').$image.'.jpg' ?>" /></li>
<?php endforeach ;} ?>
</ul>
This generates an image gallery from the central bank and works great. Sure someone more experienced than me could add some useful validation/error correction but as long as the list is written error free it works fine.
So far this is essentially a Kirby issue, this where my question begins.
Next I wanted to draw meta data for the images from a central csv sheet. E.g title, date, material ect. fields related to the $image variable.
In my csv the first column stock book code will have a figure that is equivalent to the $image variable and I want to use the rest of the information in that row to populate a series of spans that I can format and possibly animate using jquery and parse to fancy box etc.
- I need a better piece of code to generate an effective array from my csv. Possibly indexing the results by the stock book number
- And a method to query it and parse out the relevant array as a list of variable to use in the injection.
I imagined I could inject the code into the above quoted repeater.
<span class="workTitle">$title</span>
<span class="workDate">$date</span>
<span class="workMaterial">$material</span>
<span class="workDimensions">$dimensions</span>
<span class="workPrice">$price</span>
The first few lines of my csv are:
Stock book code,Date,Work Title,height,width,materials,Ownership
a-04,1962,River Barge,0,0,Oil on Board,Sold
a-08,1962,Thames Bridge Fantasy ,48,36,Oil on Board,Available
h-15,1963,Split Rocks,36,32,Oil on Board,Available
i-35,1964,Moon Dyptych,32,21,Oil on Board,Available
I haven't really got much of a clue how to finish this off. I know it's probably not super difficult but I'm no expert, certainly not when dealing with arrays. The sheet is on the server and using some php I've managed to print the csv-array result but without the header's being the array titles, they were just treated as a line, the first array in the larger array.
So really I'm looking at starting from scratch for the second part of my problem - not expecting a full cut and paste solution by any means but if someone could point me in the right direction it would be great. I haven't used j-query and don't know too much php. However I don't mind doing a lot of reading and spending the time making it work myself but I could do with a point in the right direction.
The in-complete csv-array function I found was as follows. May have to start from stratch with it:
<?PHP
function readCSV($csvFile){
$file_handle = fopen($csvFile, 'r');
while (!feof($file_handle) ) {
$line_of_text[] = fgetcsv($file_handle, 1024);
}
fclose($file_handle);
return $line_of_text;
}
// Set path to CSV file
$csvFile = 'http://localhost/peterliddle/assets/artistswork/imagemeta.csv';
$csv = readCSV($csvFile);
echo '<pre>';
print_r($csv);
echo '</pre>';
?>
This out puts this (and 300 more):
Array
(
[0] => Array
(
[0] => Stock book code
[1] => Date
[2] => Work Title
[3] => height
[4] => width
[5] => materials
[6] => Ownership
)
[1] => Array
(
[0] => a-04
[1] => 1962
[2] => River Barge
[3] => 0
[4] => 0
[5] => Oil on Board
[6] => Sold
)
[2] => Array
(
[0] => a-08
[1] => 1962
[2] => Thames Bridge Fantasy
[3] => 48
[4] => 36
[5] => Oil on Board
[6] => Available
)
[3] => Array
(
[0] => h-15
[1] => 1963
[2] => Split Rocks
[3] => 36
[4] => 32
[5] => Oil on Board
[6] => Available
)