Forum
How do I add content that can be shown or hidden on a page?
I can't figure out how to make this work. I have structured pages for a website. The top of the pages remains the same for each page. the bottom sections can be different. I have created shared content for the bottom sections. But I have no idea how to allow them to be shown or hidden on any given page.
Here is the site. Notice the [about page] (https://iswebdev.com/LC/about.php) 2 bottom sections and the [services page] (https://iswebdev.com/LC/services.php) bottom section. How can I allow the editor to choose from shared content for the bottom of my pages when using ONE master template?
I would use page attributes.
https://docs.grabaperch.com/docs/pages/page-attributes/
Set up an attribute to turn the item on or off and then test for it in the master page.
Following your advice I took the steps below. But, pages created with my master template are blank. So, something is wrong with my code.
1 - Set up a page attribute template called section_attributes.html and saved it to the perch/pages/attributes directory 2 - Added this to the default.html template in the percha/pages/attributes directory 3 - The content of the section_attributes.html file is
4 - Added the code you provided above and altered to fit my naming as below:
What am I missing? I'm sorry, but I'm not a php programmer. So, anything that is beyond html/css or perch tags is not within my knowledge.
Where did you add the code? You're using template comments which suggests to me you might have added PHP to your template. It should be in your master page.
That is added on my master page. I used comments so that I know where the structured part of the master page ends and where the other sections will begin.
Ok, so what problem are you seeing?
It returns a blank page when the code is in the master template. When I remove the code, the page resolves.
Here is the full master page template:
I'm not sure if this matters or not, but the Specialties Listing is set up as a shared item. Does that have anything to do with it?
If you have a "blank page" then you have a PHP error so you will need to look in your error log to see what the error is.
Yes, but the only addition to the page is the PHP code supplied by Drew in this thread. So, that is the problem and since he was helping me, I thought he might spot the error in the PHP since I am not a programmer. I was hoping since he asked what the output was, that he would see something that might help me.
I'm noticing that you are adding a parenthesis and semicolon after the brace where Drew's example ends with the brace (curly bracket).
Drew's example:
Your example:
The error log is how you debug PHP so if you need further help then we need to see what the actual error is. If you don't want to provide that then the end result is we have to guess, and it will take longer for you to get help.
Here is my error log:
~~~
Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 82 [16-Jul-2016 08:27:04 America/New_York] PHP Parse error: syntax error, unexpected ';' in /Volumes/OWC_Work_files/work/PHP-Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 82 [16-Jul-2016 08:29:46 America/New_York] PHP Parse error: syntax error, unexpected ';' in /Volumes/OWC_Work_files/work/PHP-Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 79 [18-Jul-2016 07:25:26 America/New_York] PHP Parse error: syntax error, unexpected ';' in /Volumes/OWC_Work_files/work/PHP-Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 79 [18-Jul-2016 07:26:09 America/New_York] PHP Parse error: syntax error, unexpected '?>' in /Volumes/OWC_Work_files/work/PHP-Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 81 [18-Jul-2016 07:27:49 America/New_York] PHP Parse error: syntax error, unexpected ';' in /Volumes/OWC_Work_files/work/PHP-Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 80 [18-Jul-2016 07:28:52 America/New_York] PHP Parse error: syntax error, unexpected ';' in /Volumes/OWC_Work_files/work/PHP-Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 80 [18-Jul-2016 07:28:55 America/New_York] PHP Parse error: syntax error, unexpected ';' in /Volumes/OWC_Work_files/work/PHP-Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 80 [18-Jul-2016 07:30:22 America/New_York] PHP Parse error: syntax error, unexpected '?>' in /Volumes/OWC_Work_files/work/PHP-Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 82 [18-Jul-2016 07:30:24 America/New_York] PHP Parse error: syntax error, unexpected '?>' in /Volumes/OWC_Work_files/work/PHP-Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 82 [18-Jul-2016 07:31:36 America/New_York] PHP Parse error: syntax error, unexpected '?>' in /Volumes/OWC_Work_files/work/PHP-Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 81 [18-Jul-2016 07:32:11 America/New_York] PHP Parse error: syntax error, unexpected ';' in /Volumes/OWC_Work_files/work/PHP-Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 80 [18-Jul-2016 07:32:37 America/New_York] PHP Parse error: syntax error, unexpected '?>' in /Volumes/OWC_Work_files/work/PHP-Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 81 [18-Jul-2016 07:33:50 America/New_York] PHP Parse error: syntax error, unexpected ';' in /Volumes/OWC_Work_files/work/PHP-Sites/dev.limousineconnection/perch/templates/pages/structured-interior-page.php on line 79
Here is the code on the master page.
<?php if (perch_page_attribute('showlist', [], true) { perch_content('specialty list'); } ?>
~~~
I tried removing the semi-colon and then I get the error of the unexpected error of the question mark and closing bracket.
So, I'm not sure how to proceed.
You're just missing a bracket:
Thank you, that gets me a bit closer. But now, it turns on, but when set to false it doesn't turn off. And, the top of my output page shows the word "true" or "false" -- from the setting of the page attributes in page details in the CMS. I'm not sure what code to show you from here.
Other odd behavior, when I remove the call to section_attributes.html from my default.php file in perch/pages/attributes the calls to jquery, bootstrap css and other files that belong in between my head tags are there.
When I include the call to section_attributes.html in the default template all the files in the head tags move to the body of the page rather than in between the head tags as it should be. I am using a feather to include the call to bootstrap and jquery.
Can you show us the exact code you're now using?
Sure:
added to default.php in pages/attributes:
created section-attributes.html in pages/attributes:
the full master page template:
global.head
And I'm using a feather to include the Bootstrap calls for CSS & JQuery
I think the issue is that your two options
true, false
are both truthy to PHP.So try this instead:
That did it!! Thank you so much for all your patience and help. It is GREATLY appreciated.