Creating Page Attributes

Permalink
I'm currently evaluating concrete 5 as a CMS option for our 6 or so websites.

And I got to the point of adding additional custom page attributes. For the sake of example lets say I want to add a pulldown menu with 2 options: Red & Blue. Selecting Red in the page editor would render a Red background and Blue a blue background.

So I rummaged through the online documentation and found this:

http://www.concrete5.org/documentation/developers/attributes/keys/...

It looked like what I wanted, but after creating a 160+ line Class file and adding two tables to the database, its starting to sound like a ridiculous amount of coding just to attach a new field to the page table essentially.

My guess is that I'm going about this the wrong way and that there's a much simpler approach. Can anyone steer me in the right direction?

Thanks in advance :)

Kind Regards

William Jamieson
Envision Systems

 
wwjamieson3 replied on at Permalink Reply
Figured it out, thanks :)
MMWeb replied on at Permalink Reply
Hi William

And might you be so kind to share your solution? I'm having the same problem.

Thank You!
Marc
wwjamieson3 replied on at Permalink Reply
Hi Marc,

To be honest I can't remember the final solution because it was so long ago. But I can tell you that it was infinitely simpler than what I was trying to do. Certainly no class nonsense required.

I'm 99% sure I figured out a way to do it within the actual product interface itself. Something like custom page attributes...

I hope this helps. Good luck mate :)

Cheers

William
jordanlev replied on at Permalink Reply
jordanlev
You don't need to code up an attribute like that documentation describes. Instead just go to Dashboard -> Pages and Themes -> Attributes, choose "select" from the list at the bottom and click the "Add" button. Then enter a handle and a name, and enter in your options (e.g. "Blue" and "Red") down at the bottom.

Now, in your theme templates you can do something like this:
<?php $color = $c->getAttribute('your_attribute_handle'); ?>
<div class="<?php echo $color; ?>">
  ...
</div>

Then in your css you can do something like this for the style:
.Red {
  color: red;
}
.Blue {
  color: blue;
}

(just make sure those css classes in your stylesheet match the exact name you put in for each value when you created the attribute in the dashboard).

Also see:
http://www.concrete5.org/community/forums/customizing_c5/themes-and...
http://www.concrete5.org/community/forums/customizing_c5/background...
http://www.concrete5.org/community/forums/themes/customising-theme-...
MMWeb replied on at Permalink Reply
Found it. Now that was easy if you know how!

Thank you very much.