Jump to content

Turning an area on content 'On' and 'Off'


Alex
 Share

Recommended Posts

I have an area of content 'Upcoming Events' which has title, text, image etc.. I want to be able to make visible on a page and then sometimes remove it.

At the moment I can unpublish an 'Upcoming Events' page and that content is removed from the page where I display it, but i still have a bunch of empty HTML tags left over.

What is the best way to have an area of content turn 'off' without leaving any trace?

Link to comment
Share on other sites

Soma is right, it all comes down to how you code it and where you put your conditionals. Feel free to post your code here and we can have better context to make suggestions.

Link to comment
Share on other sites

Hi Soma, Ryan and Marty,

So i have a page using a template named 'upcoming-exhibitions' which contains all the content.

I want to display some of that content on it's parent page (exhibitions) where i want to be able to turn on and off… so to speak.

So on my exhibitions page I currently have this:

<?php
$item = $pages->get("template=upcoming-exhibitions");
echo "<h2>{$item->title}</h2>";
echo "<img src='{$item->exhibition_image->size(100,100)->url}' alt='$item->description'/>";
echo "<p>{$item->exhibition_summary}</p>";
?>
Link to comment
Share on other sites

put a checkbox on the main page template (it's more efficient since you don't even have to call the other page)

and do this:

<?php
if($page->checkbox){
$item = $pages->get("template=upcoming-exhibitions");
echo "<h2>{$item->title}</h2>";
echo "<img src='{$item->exhibition_image->size(100,100)->url}' alt='$item->description'/>";
echo "<p>{$item->exhibition_summary}</p>";
}
?>

Or, if you still prefer to have the checkbox on the exhibitions page:

<?php
$item = $pages->get("template=upcoming-exhibitions");
if($item->checkbox){
echo "<h2>{$item->title}</h2>";
echo "<img src='{$item->exhibition_image->size(100,100)->url}' alt='$item->description'/>";
echo "<p>{$item->exhibition_summary}</p>";
}
?>
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...