PHP variables 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 UseLess on Sat Oct 07, 2006 4:05 pm

Greetings,

Well that's funny as I put this;
Code: Select all
<link href="newcss/<?php global $sitestyle; echo (!$sitestyle)?'farge':$sitestyle ?>.css" rel="stylesheet" type="text/css" />

in 'overall_header.tpl' and got this when viewing the page source;
Code: Select all
<link href="newcss/farge.css" rel="stylesheet" type="text/css" />

I then put this;
Code: Select all
$sitestyle = 'testing';

in 'includes/page_header.php' and then got this;
Code: Select all
<link href="newcss/testing.css" rel="stylesheet" type="text/css" />

when I refreshed the page.
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 tbensmann on Sat Oct 07, 2006 4:41 pm

That's weard...
I have a switcher document that set's the cookie:
<?php
setcookie ('sitestyle', $set, time()+31536000,
'/', 'i-bay.no', '0');
header("Location: $HTTP_REFERER");?>

and no matter what i do, i still get farge.css in the style, with youre code!

And a cookie should work on all sub directories?
tbensmann
Registered User
Registered User
 
Posts: 6
Joined: Sat Oct 07, 2006 2:59 pm

Postby UseLess on Sat Oct 07, 2006 5:10 pm

Greetings,

Is '$set' got from somewhere? and is that code in a template? and if so '$set' needs to be declared 'global' otherwise it will be empty....
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 tbensmann on Sat Oct 07, 2006 5:17 pm

this is switcher document, and i know that it works because i use it on my entire webpage...

but the situation is:

On my webpage www.i-bay.no i use switcher.php to alter the cookie...
This works perfect with al my pages, except for the phpbb forum which is found in i-bay.no/forum...

What i don't understand is why the cookie is not identified...

You can try: in the bottum right corner there are 3 colours... Click on green or red and the color wil change, but in the forum, nothing happends... it allways says farge which is the one that should be chosen if there is no other set...

Doesn't a cookie work on all subdomains?
tbensmann
Registered User
Registered User
 
Posts: 6
Joined: Sat Oct 07, 2006 2:59 pm

Postby UseLess on Sat Oct 07, 2006 7:34 pm

Greetings,

If the forum is in 'i-bay.no/forum' then it's not in a sub-domain, but a sub-dir off of the websites root. A sub-domain would be 'forum.i-bay.no'. And yes the cookie should work in sub-dirs and to get it to work in sub-domains you would use '.i-bay.no' as the domain name.

And for the forum have you changed 'includes/functions.php' to use the cookie and not set the style based on what is set in the ACP or what the user has set in their profile?
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 tbensmann on Sat Oct 07, 2006 7:46 pm

sorry, i ment sub-directories, i have written this question in 100 forums...

But, the cookie only alters the colours...

What could the problem be?
tbensmann
Registered User
Registered User
 
Posts: 6
Joined: Sat Oct 07, 2006 2:59 pm

Postby risca on Fri Nov 17, 2006 9:38 am

Hey all! Great mod, have helped a whole bunch...
Have a slight problem though.
I've created a separate databasetable for crossreference to a 3rd databasetable, None wich have anything to do with phpBB.
However, I need to get the template value {USERNAME} out. But, and here's the deal, I don't want the logged in user, I want the profile the user is looking at.

I'm in the template: profile_view_body.tpl

have used the following globals:
Code: Select all
<?php
global $contact, $userdata, $phpbb_root_path, $HTTP_GET_VARS; 

(I know that's not a complete php codeset, just pasted the global set)
But I'm failing to see how I can get the profile name.

What I've done is, or rather trying to, create a database in wich users can add their World of Warcraft characternames.
This was done in profile_add_body.tpl, this works, sort of... get double forms for some reason...
But now I want to use that data in the profile_view_body.tpl. Use the profile name to query the database table and return the row containing the same name as the profile, this row can contain up to 5 columns.
When I have all 5 data-entries I want to display them after the:

Code: Select all
<tr>
        <td valign="top" align="right" nowrap="nowrap"><span class="gen">{L_INTERESTS}:&nbsp;</span></td>
        <td> <b><span class="gen">{INTERESTS}</span></b></td>
      </tr>

-section in profile_view_body.tpl as separate links using the data from mysql.

I got an idea when I read your post about making template variables However, I fail to see where I can do that, and even how for that matter.
If possible it would be of interest to make the above into 5 template tags named:
{MAIN}
{ALT1}
{ALT2}
{ALT3}
{ALT4}
wich is also the ffield names in the mysql-table
help would be really appriciated.
risca
Registered User
Registered User
 
Posts: 1
Joined: Fri Nov 17, 2006 9:18 am

Postby UseLess on Sun Nov 19, 2006 12:54 pm

Greetings,

tbensmann: No idea without seeing all the code that makes up the style change option.

risca: You would be better off altering 'usercp_viewprofile.php' to get the extra information you want... or try adding this to the 'profile_view_body.tpl' file;
Code: Select all
<?php
$viewed_userprofile = $this->vars['USERNAME'];
?>

You can then use '$viewed_userprofile' to do a query on the db to obtain the users character names.
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

sql functions

Postby theman on Wed Jan 03, 2007 5:01 pm

In my tpl file i have

Code: Select all
<!-- PHP -->

echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" align=\"center\" valign=\"middle\">";
echo "<tr>";
echo "<td align=\"center\" valign=\"center\" width=\"25%\">";
$sql = "SELECT points FROM phpbb_hogwarts WHERE housename = 'Gryffindor'";   

   if (!$result = $db->sql_query($sql))
   {
      message_die(GENERAL_ERROR, "Could not get points.", '', __LINE__, __FILE__, $sql);
   }

while ( $row = mysql_fetch_array($result) )
{
echo "<b><a href=\"index.php?f=12\" class=\"nav\"><img src=\"images/gryffsm.png\" border=\"0\"></a><br /><a href=\"gryffindorcp.php\"><font color=\"red\" size=\"3\">&nbsp;{$row['points']}&nbsp; points</font></a></b>";
}
echo "</tr>";
echo "<tr>";
echo "<td align=\"center\" valign=\"center\" width=\"25%\">";
$sql = "SELECT points FROM phpbb_hogwarts WHERE housename = 'Hufflepuff'";   

   if (!$result = $db->sql_query($sql))
   {
      message_die(GENERAL_ERROR, "Could not get points.", '', __LINE__, __FILE__, $sql);
   }

while ( $row = mysql_fetch_array($result) )
{
echo "<b><a href=\"index.php?f=16\"><img src=\"images/huffsm.png\" border=\"0\"></a><br><a href=\"index.php?f=16\" decoration=\"none\"><font color=\"yellow\" size=\"3\">{$row['points']}&nbsp; points</font></a></b>&nbsp;";
}
echo "</tr>";
echo "<tr>";
echo "<td align=\"center\" valign=\"center\" width=\"25%\">";
$sql = "SELECT points FROM phpbb_hogwarts WHERE housename = 'Ravenclaw'";   

   if (!$result = $db->sql_query($sql))
   {
      message_die(GENERAL_ERROR, "Could not get points.", '', __LINE__, __FILE__, $sql);
   }

while ( $row = mysql_fetch_array($result) )
{
echo "<b><a href=\"index.php?f=19\"><img src=\"images/ravesm.png\" border=\"0\"></a><br><a style=\"color:#0066CC\" href=\"ravenclawcp.php\"><font size=\"3\">{$row['points']}&nbsp; points</font></a></b><br>";
}
echo "</tr>";
echo "<tr>";
echo "<td align=\"center\" valign=\"center\" width=\"25%\">";
$sql = "SELECT points FROM phpbb_hogwarts WHERE housename = 'Slytherin'";   

   if (!$result = $db->sql_query($sql))
   {
      message_die(GENERAL_ERROR, "Could not get points.", '', __LINE__, __FILE__, $sql);
   }

while ( $row = mysql_fetch_array($result) )
{
echo "<b><a href=\"index.php?f=21\"  ><img src=\"images/syltsm.png\" border=\"0\"><br><a style=\"color:#008000\" href=\"slytherincp.php\"><font size=\"3\">{$row['points']}&nbsp; points</font></a></b>";
}
echo "</td>";
echo "</tr><br>";
echo "</table>";

<!-- ENDPHP -->


That code draws some points info from the db.

I get a "Fatal error: Call to a member function on a non-object in c:\server\http\phpBB2\cache\tpl_subSilver.housepoints_index_body.php on line 14"

is it because of the "echo"?
Image
User avatar
theman
Registered User
Registered User
 
Posts: 21
Joined: Thu Feb 24, 2005 1:40 am

Postby UseLess on Wed Jan 03, 2007 7:07 pm

Greetings,

Templates are parsed within a function, therefore any vars such as '$db' need to be declared 'global' before they are used.
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

Previous

Return to eXtreme Styles mod tutorials

Who is online

Users browsing this forum: No registered users and 2 guests