Jump to content


* * * * * 1 votes

RESOLVED: Best way to include a custom external header/footer

include header footer

  • Please log in to reply
5 replies to this topic

#1 Bruno42

Bruno42

    n00b

  • Members
  • Pip
  • 4 posts
  • IPB Version:v3.2.x

Posted 09 February 2012 - 12:09 AM

I'm using the latest version of IPB (3.2.3) and I'm trying to embed IPB into our corporate website.

I'm editing the following template: Global Templates > globalTemplate

According to the documentation, the best way to include our external header/footer is this one:

<php>
include('../header.php');
</php>
IPB Template code....
<php>
include('../footer.php');
</php>

However, this is not working properly, because the <php> is executed before the template processing.
Therefore, I'm seeing: Header, Footer, Template code (in this order).

I tried to include the header/footer by using {parse} like this:
{parse include="../header.php"}

This is working better, but in that case I cannot pass any parameter to this script (sample: header.php?myparam=1).

Then, what is the best way:

- To include an external header/footer, allowing PHP parameters to be passed
- In my header/footer to set an IPB variable which would be available in the template

#2 Bitter

Bitter

    Final Prestige, LLC Owner

  • Support Staff
  • PipPipPipPipPipPipPipPipPipPip
  • 2,687 posts
  • Location:Connecticut
  • Real Name:Dustin Schriffert
  • IPB Version:v3.3.x

Posted 09 February 2012 - 01:32 AM

I don't have an answer to your second question, but as for the first, I use the parse include instead of just include on my board and that seems to work better for me as well.

Posted Image


#3 Bruno42

Bruno42

    n00b

  • Members
  • Pip
  • 4 posts
  • IPB Version:v3.2.x

Posted 09 February 2012 - 12:13 PM

View PostBitter, on 09 February 2012 - 01:32 AM, said:

I use the parse include instead of just include on my board and that seems to work better for me as well.

Thank you for your answer :)

By using {parse}, how do you pass parameters to the included script, for instance this does not work:

{parse include="../header.php?myparam=1"}


#4 Bruno42

Bruno42

    n00b

  • Members
  • Pip
  • 4 posts
  • IPB Version:v3.2.x

Posted 09 February 2012 - 01:48 PM

Eventually I resolved my issue, I'm sharing with you my solution:

1. Create a file header.php including 2 files

<?php
include('header-part-1.php');
include('header-part-2.php');
?>

Therefore, this file can still be used by your main site (your corporate website for instance).

2. Create header-part1.php, containing your custom header, but only the invisible part, without closing </head>:

<?php
echo
'<html>
<head>
<!-- My custom HTML code here !->';
?>

3. Create header-part-2.php containing your visible HTML code (a Navigation menu for instance):

<?php
echo '<div id="header"><ul><li>My Menu</li></ul></div>';
?>

4. Go to your Admin Panel and edit this template: Global Templates > globalTemplate

At the very beginning of the file add:

<php>global $forum; $forum = true;</php>
{parse include="../header-part-1.php"}

Please note that $forum is a global variable which can be used in header-part-1.php & header-part-2.php as a conditional variable.

Still in the same template, look for this part of the code:

</head>
<body id='ipboard_body'>

Right after, add:

{parse include="../header-part-2.php"}

5. At the very end of the template, add:

{parse include="../footer.php"}

6. Done!
Your external header/footer are now included.
<html> and <head> are handled by your main header but is taking into account all the SEO, CSS, JS from IPB.

Hopefully this will be helpful for someone else ;)

Edited by Bruno42, 09 February 2012 - 01:56 PM.


#5 Bitter

Bitter

    Final Prestige, LLC Owner

  • Support Staff
  • PipPipPipPipPipPipPipPipPipPip
  • 2,687 posts
  • Location:Connecticut
  • Real Name:Dustin Schriffert
  • IPB Version:v3.3.x

Posted 09 February 2012 - 03:03 PM

Glad to hear you resolved your issue. I think this information would be great as a reference for anyone who runs into the same situation :)

Posted Image


#6 Bitter

Bitter

    Final Prestige, LLC Owner

  • Support Staff
  • PipPipPipPipPipPipPipPipPipPip
  • 2,687 posts
  • Location:Connecticut
  • Real Name:Dustin Schriffert
  • IPB Version:v3.3.x

Posted 09 February 2012 - 03:03 PM

The issue this topic was opened for has now been resolved. :)

Posted Image





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users