Sign in to follow this  
OllieMackJames

How to include html on condition of field checked

Recommended Posts

In my template I want to exclude some html based on a field being checked.

The field landingpage is a checkbox field, and if it is checked I want to exclude the html below from showing up, how can I do that?

Thanks!

<?php if $page->landingpage=1; //If the checkbox field landingpage is checked I want to exclude the following html code:
	<!-- Top Navigation Bar -->
  <div class="site-nav">
    <div id="navcontrol" class="logobanner centered original-nav">
      <label for="navtoggle" class="navtoggle"><img src="/site/templates/img/logo.png" width="196" alt="logo" title="Menu Toggle" alt="Menu Toggle"><span class='menu-toggle-text'><?=$menu_title?></span></label>
    </div>
    <input type="checkbox" id="navtoggle"/>
    <div class="top">
      <nav class="original-nav">
        <div id="logoline" class="logobanner logobanner-original centered">
          <a href='/'><img src="/site/templates/img/logo.png" width="<?=intval($config->navLogoWidth)?>" alt="logo" style="max-width:<?=intval($config->navLogoWidth)?>px"></a>
        </div>
        <ul class="menu">
          <!--?= renderNav($page); ?-->
        </ul>
      </nav>
    </div>
</div>

 

Share this post


Link to post
Share on other sites

if $page->landingpage=0

?

see below...

 

Edited by dragan
facepalm moment

Share this post


Link to post
Share on other sites
1 minute ago, dragan said:

if $page->landingpage=0

?

 

Admittedly I don't use this PHP syntax but aren't we missing a second = ? Otherwise we are assigning instead of comparing :-).

Share this post


Link to post
Share on other sites

hehe, sorry, it's a lazy Sunday here... of course you'd use == or <1. Maybe you can even use if(!$page->field) but I'm too lazy to test

Share this post


Link to post
Share on other sites

@dragan thanks, but I don't understand yet, I tried the following but then the front end throws errors.

<?php if ($page->landingpage !== 1) echo ([  
	<!-- Top Navigation Bar -->
  <div class="site-nav">
    <div id="navcontrol" class="logobanner centered original-nav">
      <label for="navtoggle" class="navtoggle"><img src="/site/templates/img/logo.png" width="196" alt="logo" title="Menu Toggle" alt="Menu Toggle"><span class='menu-toggle-text'><?=$menu_title?></span></label>
    </div>
    <input type="checkbox" id="navtoggle"/>
    <div class="top">
      <nav class="original-nav">
        <div id="logoline" class="logobanner logobanner-original centered">
          <a href='/'><img src="/site/templates/img/logo.png" width="<?=intval($config->navLogoWidth)?>" alt="logo" style="max-width:<?=intval($config->navLogoWidth)?>px"></a>
        </div>
        <ul class="menu">
          <!--?= renderNav($page); ?-->
        </ul>
      </nav>
    </div>
  </div>
]);

 

Share this post


Link to post
Share on other sites

OK, solved, I copied the html to a file called nav.inc, then added this code to the template:

	<?php if ($page->landingpage !== 1) include ('nav.inc'); ?>
	

That did the trick.

Thanks

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.