Display custom attribute form the file manager

Permalink 2 users found helpful
Thanx!

How can I display custom attribute form the file manager

I create the Richtext attribute image_caption / Caption in the filmmaker.
Then I tried things like this to display the text with the Image

&/><p class="caption"><?php echo $img->image_caption ?></p>


but there was no output…

 
jordanlev replied on at Permalink Reply
jordanlev
Can you please provide more code -- it's impossible to tell what exactly you're trying to do here with just the one line you posted.
alphaboson replied on at Permalink Reply
Sure! I thougth this was more universal…

I played with the Designer Gallery Block,
a try to extend them for my needs.

https://github.com/jordanlev/c5_designer_gallery...

<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<?php
/* You can loop through all of the images in the chosen file set with some code like this:
 *
 *   <?php foreach ($images as $img): ?>
 *       ...
 *   <?php endforeach; ?>
 *
 * Inside the loop, the following data is available about each image:
 *   $img->title : Image's "Title" attribute (set via File Manager properties). Note that C5 sets titles to the file name upon initial upload, so you might not want to display this if you don't expect users to edit them)
 *   $img->description : Image's "Description" attribute (set via File Manager properties) -- use this for captions
 *   $img->orig->src : Original (full-size) image src
 *   $img->orig->width : Original (full-size) image width (in pixels)
 *   $img->orig->height : Original (full-size) image height (in pixels)
 *   $img->large->src : Large image src
jordanlev replied on at Permalink Reply
jordanlev
You need to call the 'getAttribute' function on the original file object. I have the designer gallery template set up in a way where this is not available in the template, though. What you should do instead is modify the controller.php file, find this line (should be line #109):
$image->descriptionRaw = $f->getDescription();

...and replace it with this line:
$image->descriptionRaw = $f->getAttribute('image_caption') ? $f->getAttribute('image_caption') : '';


Now in the template, $img->description will show your custom attribute instead of the "description" attribute. If you set up the caption as a "rich text" attribute (so user is using the rich text editor to enter content), you'll want to output the $img->descriptionRaw variable instead so their rich text is maintained.
alphaboson replied on at Permalink Reply
your way replaces the regular description attribute, right?
I want to add one or more description attributes to one image.
jordanlev replied on at Permalink Reply
jordanlev
Ah, good point. Okay, well instead of replacing things in the controller, add to them. So instead of replacing line #109 in controller.php, add a new line under it and paste this in there:
$image->caption = $f->getAttribute('image_caption') ? $f->getAttribute('image_caption') : '';

...then inside the loop in the template, do this to output the caption:
<?php echo $img->caption; ?>
alphaboson replied on at Permalink Reply
Thanx, I will try this in my new favorite CMS