Image and Slideshow Blocks Hardcoded in a theme with custom attributes

Permalink 1 user found helpful
Hello,

I'm trying to include an image, and later on a slideshow into my page. What I want is to select images from custom attributes from page properties.

This is the code I'm currently using:

<?php
      $bt_headerimage = BlockType::getByHandle('image'); 
      $bt_headerimage->render('view');
      ?>

What I do not get is how do I put the custom attribute into the image block here? I know I need to use a controller function but I can't find out how to do it.

I also found the following code, but it's resulting in an error message:
<?php
$headerimage = $cobj->getAttributeValue('headerimage');
      $bt_headerimage = BlockType::getByHandle('image'); 
      $bt_headerimage->render('view');
      ?>


I'm new with PHP so any help is appreciated!

DoorDarius
 
12345j replied on at Permalink Reply
12345j
try this
$im=loader::helper('image');
$image= $cobj->getCollectionAttributeValue('headerimage');
if (is_object($image)) {
    $im->output($image);
}
jordanlev replied on at Permalink Reply
jordanlev
Note that @12345j's answer implies that you do *not* use an image block. You need to create the page attribute via the dashboard (in his code sample that attribute would be of the "File/Image" type and have the handle "headerimage").
If you want to create a slideshow instead of just a single image, you should make a custom attribute of the type "file set" (which is not built-in to C5 but there's a free addon to add it to your system:http://www.concrete5.org/marketplace/addons/fileset-attribute... ).
DoorDarius replied on at Permalink Reply
DoorDarius
I'm still getting the following error:
Fatal error: Call to a member function getCollectionAttributeValue() on a non-object in [...].php on line 33
jordanlev replied on at Permalink Reply
jordanlev
Change $cobj to $c -- and also you can shorten that code up, like so:
$img = $c->getAttribute('headerimage');
if ($img) {
  Loader::helper('image')->output($img);
}
DoorDarius replied on at Permalink Reply
DoorDarius
Thanks 12345j and jordandev got it working with an image now.
DoorDarius replied on at Permalink Reply
DoorDarius
One other question:
I installed the fileset addon, what is the smartest thing to do if I want to hardcode the slideshow in there?
jordanlev replied on at Permalink Best Answer Reply
jordanlev
You're going to need to come up with the actual slideshow on your own. I've found the Nivo slider (http://nivo.dev7studios.com/ ) to be a good general purpose one, in case you don't have one already chosen. You'll need to learn how to make it work on the front-end -- I suggest going through the documentation and looking at their sample code and figuring out how to make it work on a separate "static" html page (one that is just a standalone page, having nothing to do with Concrete5 or PHP).

After you understand that, I'd try to make it work in your theme but just using a few static images as examples (so don't worry about the file set or letting the user choose anything at this point -- just make it work with 3 or 4 pre-selected images you have).

After you have the front-end working on your concrete5 theme, THEN change the static images you are using as an example with images from the file set attribute. Here's how you do that:
<?php
$files = array();
$fsID = $c->getAttribute('your_fileset_attribute_handle');
if ($fsID) {
   Loader::model('file_set');
   Loader::model('file_list');
   $fs = FileSet::getByID($fsID);
   $fl = new FileList();      
   $fl->filterBySet($fs);
   $fl->setPermissionLevel('canRead');
   $fl->sortByFileSetDisplayOrder();
   $files = $fl->get();
}
?>
<ul class="slideshow_container_example">


You'll need to tweak the lower portion of that code to fit your particular slideshow, but that's how you get the images out of the file set attribute.

Good luck!
DoorDarius replied on at Permalink Reply
DoorDarius
Thanks, this works perfectly!

Left it alone for a while, but now I can add all content from page properties for my portfolio!
jordanlev replied on at Permalink Reply
jordanlev