Forum
User setting Black or White page
I want my user to choose if the page is a White page or a Black page, at the moment I've got that set as an attribute so they can change it themselves and it changes the stylesheet.
This works fine as a rule, however I also need to change things in Layouts and PHP pages. But the attribute is set in a Content Template I don't see how I can effectively use that in the pages above (as it were).
The only way I can think of doing it is to have two versions of every Master Page, one with a Black attribute set and another with a White one, obviously that doubles changes work so does anyone have a better idea?
Thanks, Chris.
Are you using a page attribute for this?
Yeah, at the moment I've got the following in a page attribute.
Ok - and in which context are you having problems using that?
That works fine but only changes the stylesheet. I need the whole page to be aware that it is black or white so that it can get images from another directory.
I sort of need it as a system variable I suppose, but then I wouldn't know where the user could set it per page or how to then use that in both php and HTML templates.
You can use
perch_page_attribute()
to get that attribute back:or
or assign it into a template:
and then use it in the template:
https://docs.grabaperch.com/docs/pages/page-attributes/page-functions/perch-page-attribute/
Great thanks, thats almost worked, if I use it as a simple replacement ie
But it always prints to the screen, so I can't use it for if else statements or even add it to a system variable. When I do I just get 'white' or 'black' appear in text at the top of the page.
This will return:
This will echo:
So this:
should be this:
I agree that should be the case but it isn't, the true doesn't appear to change anything, it always echos.
In one of my templates that I use in a layout file its coded like this:
However the if else doesn't work and it outputs both images and at the top of the page before <html> there is simply 'black'.
I've set this in the header layout file, which is where the template should be reading it from.
The only reason I've added it to a variable is just to test that wasn't the problem.
In fact more reason seems to suggest that this line is what gets echo'd.
Oh, sorry, my mistake. The second parameter is an options array. Set
true
as the third parameter to return.Awesome, nailed it thanks!