Jump to content


Photo

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

solved

  • Please log in to reply
6 replies to this topic

#1 Alex

Alex

    Full Member

  • Members
  • PipPipPip
  • 81 posts
  • 5

  • LocationMelbourne, Australia

Posted 22 May 2012 - 09:11 AM

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?

#2 Soma

Soma

    Hero Member

  • Moderators
  • 3,397 posts
  • 1929

  • LocationSH, Switzerland

Posted 22 May 2012 - 09:30 AM

Depends on how you code that part. :)

So I'd guess (without seeing your code) you have some echos in there that isn't conditional.

@somartist | modules created | support me, flattr my work flattr.com


#3 ryan

ryan

    Hero Member

  • Administrators
  • 5,980 posts
  • 3380

  • LocationAtlanta, GA

Posted 22 May 2012 - 11:03 AM

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.

#4 Marty Walker

Marty Walker

    Sr. Member

  • Members
  • PipPipPipPip
  • 347 posts
  • 165

  • LocationKatoomba, AU

Posted 22 May 2012 - 07:46 PM

You could setup a checkbox field called "hidden" and only show it if it's unchecked.

<?php
$items = $pages->get("/page/")->find("hidden=0");
echo "<div><p>content</p></div>";


#5 Alex

Alex

    Full Member

  • Members
  • PipPipPip
  • 81 posts
  • 5

  • LocationMelbourne, Australia

Posted 23 May 2012 - 06:46 AM

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>";
?>


#6 diogo

diogo

    Hero Member

  • Moderators
  • 2,068 posts
  • 1179

  • LocationPorto, Portugal

Posted 23 May 2012 - 09:24 AM

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>";
}
?>


#7 Alex

Alex

    Full Member

  • Members
  • PipPipPip
  • 81 posts
  • 5

  • LocationMelbourne, Australia

Posted 24 May 2012 - 07:31 AM

Ah checkbox, so simple so effective... thanks all

Alex





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users