How to use php in templates

Tutorials for <a href="http://www.phpbbstyles.com/viewtopic.php?t=356">eXtreme Styles mod</a> for phpBB 2.0.

Moderator: Moderators

Postby CrazyCow007 on Thu Apr 27, 2006 1:33 am

[quote user="CrazyCow007" post="71550"]Hi everybody !

I've a problem to include this PHP code in my overall header :

Code: Select all
<?php
if (eregi('msie', $HTTP_USER_AGENT) && !eregi('opera', $HTTP_USER_AGENT))
{
// Internet Explorer
echo ("<link rel=\"stylesheet\" href=\"http://www.jamesbond-fr.com/images/emx_nav_right_ie.css\" type=\"text/css\" />");
}
else
{
echo ("<link rel=\"stylesheet\" href=\"http://www.jamesbond-fr.com/images/emx_nav_right.css\" type=\"text/css\" />");
}
?>


On normal pages it works great but with eXtreme Styles it always return the emx_nav_right.css CSS file. Do you know if my code is possible to include to my phpBB forum ? :P

Many thanks in advance ! :wink:[/quote]

I've still the same problem :(
CrazyCow007
Registered User
Registered User
 
Posts: 2
Joined: Fri Mar 10, 2006 7:00 pm

Postby wdfadude on Sat Apr 29, 2006 4:39 pm

I have the extreme styles mod installed, and it works like a charm. I also have a php include call in in the overall_header.tpl template, and it brings up the include okay but only executes HTML in it -- not any PHP code. Here is what I'm trying to do:

I want to have ONE header menu file used across my site, even on non-phpBB pages. On those non-phpBB pages, this header works perfectly, but I can't get it to work on phpBB pages.

In overall_header.tpl, I'm calling an include menu.php.

In menu.php, I have code such as this (I've condensed it down a bit):

Code: Select all
<table>
  <tr>
<?php If ($sectionname=="main") { ?>
  <td class="navon"><a href="../index.php" class="topon">Home</a></td>
  <td class="navoff"><a href="../phpBB/" class="topoff">Forums</a></td>
  <td class="navoff"><a href="../contact-us/" class="topoff">Contact Us</a></td>
  <td class="navoff"><a href="../site-map/" class="topoff">Site Map</a></td>
<?php } Else If ($sectionname=="forums") { ?>
  <td class="navoff"><a href="../index.php" class="topoff">Home</a></td>
  <td class="navon"><a href="../phpBB/" class="topon">Forums</a></td>
  <td class="navoff"><a href="../contact-us/" class="topoff">Contact Us</a></td>
  <td class="navoff"><a href="../site-map/" class="topoff">Site Map</a></td>
.
.



...and so on.

In phpBB site pages, such as phpBB/index.php, I've tried to declare variables at the top of the code like this so that the menu will appear as I want to on that specific page:

Code: Select all
<?php
$sectionname="forums";
.
.
.


Like I said, only the HTML code in menu.php will appear when the page is brought up in a browser. How can I get PHP in an include file to execute when variables are declared before the call for overall_header.tpl?
wdfadude
Registered User
Registered User
 
Posts: 3
Joined: Sat Apr 29, 2006 4:38 pm

Postby UseLess on Sat Apr 29, 2006 9:52 pm

Greetings,

The template is parsed inside a function therefore the var you declare in 'index.php', '$sectionname="forums";' for example will need to be declared global in the script... so you'd add;

Code: Select all
global $sectionname;


to this;

Code: Select all
<table> 
<tr> 
<?php [highlight]global $sectionname;[/highlight]
If ($sectionname=="main") { ?> 
<td class="navon"><a href="../index.php" class="topon">Home</a></td> 
<td class="navoff"><a href="../phpBB/" class="topoff">Forums</a></td> 
<td class="navoff"><a href="../contact-us/" class="topoff">Contact Us</a></td> 
<td class="navoff"><a href="../site-map/" class="topoff">Site Map</a></td> 
<?php } Else If ($sectionname=="forums") { ?> 
<td class="navoff"><a href="../index.php" class="topoff">Home</a></td> 
<td class="navon"><a href="../phpBB/" class="topon">Forums</a></td> 
<td class="navoff"><a href="../contact-us/" class="topoff">Contact Us</a></td> 
<td class="navoff"><a href="../site-map/" class="topoff">Site Map</a></td>
Movie Quote:
It's not the years honey, it's the mileage...

I do not provide any install services for phpBB, Mods or Styles.
Please do not pm me for support/scripting help - you won't get any reply. If you have a question then make a post in the appropriate forum.
User avatar
UseLess
Registered User
Registered User
 
Posts: 6220
Joined: Mon Sep 27, 2004 2:14 am
Location: North East, UK

Postby wdfadude on Sun Apr 30, 2006 8:22 pm

Thanks, UseLess! It works great!

I've been playing around with the menu.php include file, and I'm wanting to add a submenu to it. Of course, with the phpBB specific submenu items, it will show "login" and "register" if the person has not logged in or registered yet, and will show things like "private messages" and "my profile" if they are logged in. Is there an easy way to add these:

Code: Select all
<!-- IF LOGGED_IN -->
.
("private messages" and "my profile" links go here)
.
<!-- ENDIF -->


and

Code: Select all
<!-- BEGIN switch_user_logged_out -->
.
("login" and "register" links go here)
.
<!-- END switch_user_logged_out -->


in the external php file? Please excuse me if I'm going way off topic with this request, or if this has already been answered in another thread. Thanks!
wdfadude
Registered User
Registered User
 
Posts: 3
Joined: Sat Apr 29, 2006 4:38 pm

Postby DooBDee on Sun Apr 30, 2006 8:50 pm

PHP way to do it:
Code: Select all
<?php
global $userdata;
if ( !$userdata['session_logged_in'] )
{
  // user logged out
}
else
{
  // user logged in
}
DooBDee
Website Ninja
DooBDee.net
User avatar
DooBDee
Moderator
Moderator
 
Posts: 3530
Joined: Tue Mar 01, 2005 6:28 pm
Location: DooBDee.net

Postby wdfadude on Sun Apr 30, 2006 9:28 pm

[quote user="DoobDee" post="74772"]PHP way to do it:
Code: Select all
<?php
global $userdata;
if ( !$userdata['session_logged_in'] )
{
  // user logged out
}
else
{
  // user logged in
}
[/quote]

Brilliant! Thanks, people!
wdfadude
Registered User
Registered User
 
Posts: 3
Joined: Sat Apr 29, 2006 4:38 pm

Previous

Return to eXtreme Styles mod tutorials

Who is online

Users browsing this forum: No registered users and 2 guests