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

Getting closer

Postby jarrod on Wed Jan 04, 2006 11:30 pm

Thankyou for your speedy response, although I can't say it's working.
Do I need to declare anything as global?
jarrod
Registered User
Registered User
 
Posts: 10
Joined: Wed Jan 04, 2006 10:57 pm

Postby UseLess on Thu Jan 05, 2006 12:17 am

Greetings,

Your inside a loop... so the 'POST_SUBJECT' should be 'postrow.POST_SUBJECT'
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

So close now I can smell it

Postby jarrod on Thu Jan 05, 2006 12:29 am

err, once again thanks for your efforts but it still isn't quite doing what I thought it would, it can't find the variable, I currently have

Code: Select all
<td width="100%" height="28" valign="middle" bgcolor="#FFFFFF"> 
<?php   
if( $this->vars['postrow.POST_SUBJECT'] == 'Photo' )
{     
echo '<span style="margin:0px;" class="postbody">';   

else 
{     
echo '<span style="margin:3px;" class="postbody">';   

?> 
       {postrow.MESSAGE}</span>{postrow.ATTACHMENTS} 
       </td>
jarrod
Registered User
Registered User
 
Posts: 10
Joined: Wed Jan 04, 2006 10:57 pm

Postby UseLess on Thu Jan 05, 2006 8:47 am

Greetings,

Try;

[code start="3"]if( $postrow_item['POST_SUBJECT'] == 'Photo' )[/code]
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

Still not quite right

Postby jarrod on Thu Jan 05, 2006 12:34 pm

Afraid not, this is getting more puzzling by the minute
jarrod
Registered User
Registered User
 
Posts: 10
Joined: Wed Jan 04, 2006 10:57 pm

Actually that did the trick

Postby jarrod on Thu Jan 05, 2006 12:37 pm

I apologise for the above post, after several refreshes the page updated with the required result, thanks immensely :D
jarrod
Registered User
Registered User
 
Posts: 10
Joined: Wed Jan 04, 2006 10:57 pm

Another problem

Postby jarrod on Sat Jan 07, 2006 8:04 pm

How could I affect the layout of a single post by a partial match on it's subject name, ie anything containg "right", and then shorten the subject, so that
"right post1" "right post2" and "post3" became "post1" "post2" and "post3".

I don't know if it's possible actually, it must need a function like str_replace to shorten the posts, it's the selecting a partial match that really has me stumped
jarrod
Registered User
Registered User
 
Posts: 10
Joined: Wed Jan 04, 2006 10:57 pm

Postby thedestroyer on Thu Feb 02, 2006 7:25 pm

I have this code in my file overall_header.tpl

Code: Select all
<?php
   global $board_config;
   global $HTTP_COOKIE_VARS;

   $cookiename = $board_config['cookie_name'] . '_quickmsg';
   $cookiepath = $board_config['cookie_path'];
   $cookiedomain = $board_config['cookie_domain'];
   
   $quickmsg = $HTTP_COOKIE_VARS[$cookiename];
   if($quickmsg != "")
   {
       $current_time = time();
       list($qmsg_title, $qmsg_msg) = explode(",", urldecode($quickmsg), 2);
?>
<div style="top: 5px;" id="quickmsg">
<table class="forumline" width="100%" cellspacing="1" cellpadding="4"

border="0" onclick="hidediv('quickmsg');">
   <tr>
      <th class="thHead" height="25"><?php echo $qmsg_title; ?></th>
   </tr>
   <tr>
      <td class="row1"><table width="100%" cellspacing="0" cellpadding="1"

border="0">
         <tr>
            <td align="center"><span class="gen">
                <?php echo $qmsg_msg; ?>
                </span></td>
         </tr>
      </table></td>
   </tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
<!--

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
deleteCookie(
    <?php echo '"'.$cookiename.'", "'.$cookiepath.'", "'.$cookiedomain.'"';

?>
);
// -->
</SCRIPT>             
</div>
<?php    } ?>


It doesn't work, why?
thedestroyer
Registered User
Registered User
 
Posts: 2
Joined: Thu Feb 02, 2006 7:23 pm

Fairly simple question

Postby jarrod on Wed Feb 15, 2006 8:50 pm

In the overall header.tpl file, how would I refer to the "{SITENAME}" or "{PAGE_TITLE}"? through php?
jarrod
Registered User
Registered User
 
Posts: 10
Joined: Wed Jan 04, 2006 10:57 pm

Postby cotp on Mon Jul 31, 2006 5:10 pm

Hello all :)
I am trying to use an if condition in a template and I am having problems.
I have a mysql query on a page where I get variable $hf

Then on a template I want to do

Code: Select all
<select name="{INFO}" class="post" id="{INFO}">
          <?php  echo "<option value=\"1\""; if ($hf == "1" ) { echo "selected";} echo ">Homme</option>"; ?>
         <?php  echo "<option value=\"2\""; if ($hf == "2" ) { echo "selected";}  echo ">Femme</option>"; ?>
</select>


I have tried an echo with variable hf but it doesn't seem to be there ... :(

Can someone be kind to explain me what I am doing wrong ?

Thanks in advance

Cotp
Cotp is webmaster of a forum cinema in french and of the official site of David Mc Neil

PHPBB 2.0.21 version
cotp
Registered User
Registered User
 
Posts: 1
Joined: Mon Jul 31, 2006 5:04 pm

Postby pentapenguin on Tue Sep 26, 2006 7:06 am

You need to use
Code: Select all
global $hf;

Explanation: http://www.php.net/global
User avatar
pentapenguin
Moderator
Moderator
 
Posts: 1466
Joined: Tue Sep 14, 2004 4:15 pm
Location: Georgia, USA

Postby tbensmann on Sat Oct 07, 2006 3:00 pm

Question!

I use a cookie to determin the css of my webpage. People can choose a color, or the the standerd css is used.

But this does not seem to work within the phpbb template. I use the eXtreme Styles MOD and the php code does work on all my other pages. Here is the sample code that chooses a image with a cookie (that works on all my other pages).

Code:
Code: Select all
<link href="newcss/<?php echo (!$sitestyle)?'farge':$sitestyle ?>.css" rel="stylesheet" type="text/css" />



The code is found in overall_header.tpl

Can anyone tell me why this doesn't work in the phpbb?
tbensmann
Registered User
Registered User
 
Posts: 6
Joined: Sat Oct 07, 2006 2:59 pm

Postby UseLess on Sat Oct 07, 2006 3:06 pm

Greetings,

The answer is;

The templates in phpBB are parsed within a function, therefore any variables MUST be declared 'global' if they are to be used. So your code should be;
Code: Select all
<link href="newcss/<?php global $sitestyle; echo (!$sitestyle)?'farge':$sitestyle ?>.css" rel="stylesheet" type="text/css" />
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 3:19 pm

it doesn't work... Any other ideas?
tbensmann
Registered User
Registered User
 
Posts: 6
Joined: Sat Oct 07, 2006 2:59 pm

Postby tbensmann on Sat Oct 07, 2006 3:52 pm

Can anyone please help me?!?!?
tbensmann
Registered User
Registered User
 
Posts: 6
Joined: Sat Oct 07, 2006 2:59 pm

PreviousNext

Return to eXtreme Styles mod tutorials

Who is online

Users browsing this forum: No registered users and 2 guests