0

Im a beginner in php and want to get help from you guys here, I have a php include tag which i want it to be between a html tag and both of them between a php if tag ... I have tried this and is giving erro, please help.

<?php if ($menu->getActive() == $menu->getDefault()) ?>
<section class="content">
<?php { include '_include-content.php'; } ?>
</section>
<?php endif ?>
1
  • 1
    you missing : at the end. it should look like: <?php if ($menu->getActive() == $menu->getDefault()) : ?> Commented Nov 7, 2013 at 13:58

4 Answers 4

2

Do like this [Enclose any HTML content inside echo statement.]

<?php 
if ($menu->getActive() == $menu->getDefault()) 
{
echo "<section class='content'>";
include '_include-content.php';
echo "</section>";
}
?>
Sign up to request clarification or add additional context in comments.

Comments

1

According to
http://www.php.net/manual/en/control-structures.if.php
http://www.php.net/manual/en/control-structures.alternative-syntax.php

<?php if ($menu->getActive() == $menu->getDefault()): ?>
    <section class="content">
        <?php include '_include-content.php'; ?>
    </section>
<?php endif ?>

or

<?php if ($menu->getActive() == $menu->getDefault()){ ?>
    <section class="content">
        <?php include '_include-content.php'; ?>
    </section>
<?php } ?>

should work fine..

1 Comment

I have to wait for a bit, it says i need to :p
1

The PHP if function works as follow

if (conditions) {
  // do sth
}

or

if (conditions):
  // do sth
endif;

You made a mix using the brackets and endif so for your Problem, try:

<?php if ($menu->getActive() == $menu->getDefault()) { ?>
<section class="content">
<?php include '_include-content.php'; ?>
</section>
<?php } ?>

I suggest this syntax because it is normally used.

For your problem, see the note in http://php.net/manual/en/control-structures.alternative-syntax.php

Note: Mixing syntaxes in the same control block is not supported.

Comments

1
<?php if ($menu->getActive() == $menu->getDefault()){ ?>
    <section class="content">
        <?php include '_include-content.php'; ?>
    </section>
<?php } ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.