Adding File Manager Images via page template
Permalink
I've got a site where I'd like to assign a background image based on the section of the site.
For a sitemap that looks like this:
HOME
--ABOUT
--PRESS
----PAGE 1
----PAGE 2
----PAGE 3
--CONTACT
I've got the page types adding a body id that matches the section name, so PRESS and PAGE 1 both have a <body id="press"> That code looks like this:
What I was thinking was that I'd upload an image to the file manager, which I'd title "press." Then I could write some PHP in the template that says, in effect, "find an image in the file manager with a title that matches the body ID."
So I'm wondering if that's possible, and if this would be the best way to accomplish this. I thought about adding a Custom Attribute and manually selecting an image from the file manager, but I don't think you can have a custom attribute cascade down to children pages. Then the problem becomes, when you create new pages, they wouldn't have a file selected.
Any suggestions would be appreciated!
Thanks.
For a sitemap that looks like this:
HOME
--ABOUT
--PRESS
----PAGE 1
----PAGE 2
----PAGE 3
--CONTACT
I've got the page types adding a body id that matches the section name, so PRESS and PAGE 1 both have a <body id="press"> That code looks like this:
<body id="<?php $f = preg_split('/\//', $c->getCollectionPath()); echo $f[1] ?>">
What I was thinking was that I'd upload an image to the file manager, which I'd title "press." Then I could write some PHP in the template that says, in effect, "find an image in the file manager with a title that matches the body ID."
So I'm wondering if that's possible, and if this would be the best way to accomplish this. I thought about adding a Custom Attribute and manually selecting an image from the file manager, but I don't think you can have a custom attribute cascade down to children pages. Then the problem becomes, when you create new pages, they wouldn't have a file selected.
Any suggestions would be appreciated!
Thanks.
Thanks for this. I think this is definitely on the right track.
I've set up a custom attribute called header_image. It's an image/file attribute, with which I can select an image from my file manager.
Say I add this attribute to my PRESS page, for example. The pages below that (PAGE 1, PAGE 2) should look to see if they have their own header_image attribute. If they do, use it. If not, start looking up the chain to find the nearest parent page with that attribute.
The first part of your code seems to do something similar, though it's looking for an ID, rather than an image path.
Where I'm stuck right now is on how to get this code to return the path to the resulting image. Then I can write a style like:
But I'm having some trouble finding that.
I've set up a custom attribute called header_image. It's an image/file attribute, with which I can select an image from my file manager.
Say I add this attribute to my PRESS page, for example. The pages below that (PAGE 1, PAGE 2) should look to see if they have their own header_image attribute. If they do, use it. If not, start looking up the chain to find the nearest parent page with that attribute.
The first part of your code seems to do something similar, though it's looking for an ID, rather than an image path.
Where I'm stuck right now is on how to get this code to return the path to the resulting image. Then I can write a style like:
#banner {background-image: url(<?php echo $si; ?>);
But I'm having some trouble finding that.
Okay, I think I can simplify my requirement a little more. I don't think I need the conditional statement. I can just have a template that says "display the image from the 'page_header' custom attribute of the parent page."
So if my sitemap is:
HOME
--BLOG
----Blog Entry
the Blog Entry template would need logic that says "display the header_image from BLOG"
Does anybody know how to get that image path?
Thanks
So if my sitemap is:
HOME
--BLOG
----Blog Entry
the Blog Entry template would need logic that says "display the header_image from BLOG"
Does anybody know how to get that image path?
Thanks
With a little bit of custom coding, you can cascade attributes from parents. This is how I do it
In each page type template I have this:
I'm interested in getting the nearest page that has the attribute "section index" - I use this for a section-specific custom autonav. The master collection if prevents problems when setting page defaults.
Here's the relevant contents of my elements/functions.php
The first part is some custom things I needed for working with aliases, the bulk of what you need is the while loop. Section_index is just a boolean (checkbox) value.
$si now contains the page object that has an attribute of "section_index". Then in my hard-coded autonav I have the following:
You could adopt a similar system to look for an attribute called "page background" if it was found, use it - if not find a parent that has it set (or go up the tree all the way to the homepage).
This also allows you to give a child of a section index it's own attribute.
Hope that helps!