Here is the issue there are 3 files
1. head.php
2. nav.php
3. footer.php
Problem is if user logged in
then i want to show the different layout structure if not then another structure. What I'm doing is i don't want to repeat views like html opening or closing tag in every file so that's why I'm creating partial files for that like head.php
and so on. So it's a problem in control structure statement if else
clause, It is written on head.php
file and there are errors come.
Parse error: syntax error, unexpected end of file in head.php
Parse error: syntax error, unexpected 'endif' (T_ENDIF), expecting end of file footer.php
I know PHP says write if else
clause on the same file and end it. But is there a way to solve this problem.
Code head.php:
<?php $loggedIn = false; ?>
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta http-equiv="content-type" content="text/html" charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale =1, shrink-to-fit=no">
<title>Title</title>
</head>
<body>
<?php if (!$loggedIn) : ?>
<p>You are not logged in </p>
<?php require 'footer.php'; ?>
<?php else :
require 'nav.php';
require 'footer.php.php'; ?>
Code nav.php:
<nav>
<ul>
<li><a href="">Home</a></li>
<li><a href="">Logged Out</a></li>
</ul>
</nav>
Code footer.php:
</body>
</html>
<?php endif; ?>
You are not logged in
` – Ahmad Hussnain Sep 02 '17 at 09:33