PHP help needed on very simple issue
Permalink
I want to pull a page attribute (image) to load into a css object in the header. The css code looks like this:
and my php, like this:
and it doesn’t work. I've tried, I really have. I've analyzed the semicolons and the parens and Im lost. Im calling it in the header, of course.
Help,
steve
<style> #content: background-image: url(images/art2.jpg); </style>
and my php, like this:
and it doesn’t work. I've tried, I really have. I've analyzed the semicolons and the parens and Im lost. Im calling it in the header, of course.
Help,
steve
Just a random guess (I haven't tried and verified it) but, would adding an echo on attribute work?
That gets me a blank page.
try are you sure you're using the correct syntax for loading the javascript? do you have a link we could see?
<style> #content{ background-image: url(<?php echo $c->getAttribute('background')->getVersion()->getRelativePath());?>) } </style>
javascript?
I thought it was php.
I thought it was php.
don't think there is a {speed} declaration in css or php, so I assubmed you were using supersized or something like that.
The url is:http://greenpedals.c5themepark.com/...
this is without the code because if I put that in the page doesn’t render.
steve
this is without the code because if I put that in the page doesn’t render.
steve
this works:
but that’s not what I need. An image would have to be called from its attribute.
<style type="text/css"> #content{background-color: red;} </style>
but that’s not what I need. An image would have to be called from its attribute.
<style> #content{ background-image: url(<?php echo $c->getAttribute('background')->getVersion()->getRelativePath();?>) } </style>
Thanks, but blank page.
BTW, Im loving your new blocks.
steve
BTW, Im loving your new blocks.
steve
if you view source on the blank page, are there any php errors being output?
Yes! finally:
Line 17 is the code line between the style calls.
Thanks,
steve
Fatal error</b>: Call to a member function getVersion() on a non-object in <b>/home/harris7/public_html/greenpedals/themes/theme_greenpetals/elements/header.php</b> on line 17
Line 17 is the code line between the style calls.
Thanks,
steve
that error should only happen if the attribute is not defined on that
page or the attribute isn't installed- can you check that?
On 5/12/11 10:18 PM, Concrete5 Community wrote:
page or the attribute isn't installed- can you check that?
On 5/12/11 10:18 PM, Concrete5 Community wrote:
A little page I made to help some of my co workers work with attributes, the idea was to quickly easily copy the snippets from this file.
http://cantanogames.com/c5/attributes.html...
For your example, all you should need is this:
You don't need getVersion()->, because if you take a look at getRelativePath, it automatically takes care of it for you.
Also note, that I test to make sure that the attribute exists before using it. Very important you do that with all code.
Yes, I use short tags :p
http://cantanogames.com/c5/attributes.html...
For your example, all you should need is this:
<? if($file = $c->getAttribute('background') ) { ?> <style> #content{ background-image: url(<?=$file->getRelativePath();?>); } </style> <? } ?>
You don't need getVersion()->, because if you take a look at getRelativePath, it automatically takes care of it for you.
Also note, that I test to make sure that the attribute exists before using it. Very important you do that with all code.
Yes, I use short tags :p
Thanks to all of you for your help. And thanks to Raverix for the correct way of doing this and the mini-tut.
So I'm taking it that if you call an attribute you have to test as to whether it exists or not. I thought that if it didn’t find anything it would just skip it.
I understand php a little better since starting project.
Thanks again,
steve
So I'm taking it that if you call an attribute you have to test as to whether it exists or not. I thought that if it didn’t find anything it would just skip it.
I understand php a little better since starting project.
Thanks again,
steve