oktam yoqubov
oktam yoqubov

Reputation: 29

how to use multiple header and footer in php site?

I have a PHP website, and I want to use several header and footer for this script templates. So how can I do this?

At the moment my index.php is called header.php and footer.php, and I want to use this only for the home page and the other page is to call the header-one.php and the footer-one.php (example). Can I do this?

Example my index.php code.

<?php
$view->title = $LANG["HOMEPAGE_TITLE"];

$view->description = $LANG["HOMEPAGE_DESCRIPTION"];

$view->keywords = $LANG["HOMEPAGE_TAGS"];

$view->header = $view->render(DIR_TEMPLATE.WEBSITE_TEMPLATE.'/header.php');

$view->footer = $view->render(DIR_TEMPLATE.WEBSITE_TEMPLATE.'/footer.php');

echo $view->render(DIR_TEMPLATE.WEBSITE_TEMPLATE.'/index.php');
?>

Upvotes: 0

Views: 439

Answers (1)

Touheed Khan
Touheed Khan

Reputation: 2151

You can put condition on rendering template. I've shown you example if $user is admin then render header_admin.php and footer_admin.php if not then load header.php footer.php.

if($user === 'admin')
    $view->header = $view->render(DIR_TEMPLATE.WEBSITE_TEMPLATE.'/header_admin.php');
else
    $view->header = $view->render(DIR_TEMPLATE.WEBSITE_TEMPLATE.'/header.php');

if($user === 'admin')
    $view->footer = $view->render(DIR_TEMPLATE.WEBSITE_TEMPLATE.'/footer_admin.php');
else
    $view->footer = $view->render(DIR_TEMPLATE.WEBSITE_TEMPLATE.'/footer.php');

Upvotes: 1

Related Questions