Page Attribute's with type Image/File not accessable
Permalink
I added a page attribute of type image/file named "Header Image", handle "header_image".
When reading the value using $c->getCollectionAttributeValue('header_image');
it's empty.
I tested with other type's like text and then everything works fine.
When reading the value using $c->getCollectionAttributeValue('header_image');
it's empty.
I tested with other type's like text and then everything works fine.
by looking at your code - you probably have to use $_c instead of $c but I have no clue where you want to use that code...
in auto nav the iterator uses $_c and not $c.. post the complete code otherwise, might be easier to find your problem..
in auto nav the iterator uses $_c and not $c.. post the complete code otherwise, might be easier to find your problem..
I have a template for landingpages, each landing page has a image. I want to be able to refer tot the image as a page attribute.
So create a page, choose the template, go to properties and select image as attribute.
In the template self the attribute is red and the image wil be shown.
This is not working...
I'm able to read al page attributes except of type image/file.
sample:
** atribute type text name 'test'
works!!
** existing atribute type text name 'meta_title'
works!!
** existing atribute type image/file name 'header_image'
does not work!!
So create a page, choose the template, go to properties and select image as attribute.
In the template self the attribute is red and the image wil be shown.
<img src="<?php echo $c->getCollectionAttributeValue('header_image') ?>" alt=""/>
This is not working...
I'm able to read al page attributes except of type image/file.
sample:
** atribute type text name 'test'
$c->getCollectionAttributeValue('test');
works!!
** existing atribute type text name 'meta_title'
$c->getCollectionAttributeValue('meta_title');
works!!
** existing atribute type image/file name 'header_image'
$c->getCollectionAttributeValue('header_image');
does not work!!
$steak = new CollectionAttributeKey(); $steak->getByHandle('header_image'); echo($steak);
or if it lets you, looks like it should
echo($c->getAttribute('header_image'));
Since the $c is the collection getAttribute should get Attribute for the collection
But that type of attribute is treated differently from getCollectionName and stuff like that, those are kind of standard "attributes" that all pages by default have available to use.
If that doesn't work, hey at least i tried :)
Sorry tried both, doesn't work.
Is it possible that it has to do with the image\file type of the field. Is there a different approach for that?
I've search trough the doc's and www didn't find anything... I should be an easy to use feature.
also tried
http://www.concrete5.org/community/forums/customizing_c5/using_page...
no succes.....
Is it possible that it has to do with the image\file type of the field. Is there a different approach for that?
I've search trough the doc's and www didn't find anything... I should be an easy to use feature.
also tried
http://www.concrete5.org/community/forums/customizing_c5/using_page...
no succes.....
it is easy to use this feature...
you get an image object when you get an image attribute!!
returning a simple string doesn't make much sense since a file object has many more properties.. like a thumbnail, width, height, an original file name etc.
this stuff needs an object and therefore c5 returns (as it should) an object and not only a string!
check you the code I've mentioned above and you find stuff like this:
you get an image object when you get an image attribute!!
returning a simple string doesn't make much sense since a file object has many more properties.. like a thumbnail, width, height, an original file name etc.
this stuff needs an object and therefore c5 returns (as it should) an object and not only a string!
check you the code I've mentioned above and you find stuff like this:
$picActive = $_c->getCollectionAttributeValue('picture_active'); echo $picActive->getFileRelativePath()
I haven't delved through this sort of thing so it was a shoot from the hip guess :)
Anywho, thank you for the code, I will add to it my snippet collection, I have one you might be interested in :)
Anywho, thank you for the code, I will add to it my snippet collection, I have one you might be interested in :)
I'd love to have a look at that snippet collection!
We might even be able to create a little cheatsheet someday...
We might even be able to create a little cheatsheet someday...
Of course, i'd love to... everything helps to learn...
yes it is at it should be but i'm not really familiar with the API yet.... thanks it works like a charm
you don't have to be familiar with the api but if things like that happen, try using print_r. It displays all the properties (not methods though) and you'll realize quickly that there's "more" than just a simple string...
you also see the class and from there you can simple go to the api without having a huge knowledge about the c5 architecture. open the php/api doc and you'll see all the methods you need..
you also see the class and from there you can simple go to the api without having a huge knowledge about the c5 architecture. open the php/api doc and you'll see all the methods you need..
I'm trying to do the same thing. Pull an image/ page attribute.
I used your above code
And I get this error
I used your above code
$picActive = $_c->getCollectionAttributeValue('page_background'); echo $picActive->getFileRelativePath();
And I get this error
Fatal error: Call to a member function getCollectionAttributeValue() on a non-object on line 83
I didn't have
to load in the attributes in the first place. It's working now, thanks!
Loader::model('collection_attributes');
http://www.concrete5.org/index.php?cID=5026...
it displays images instead of text in auto nav...