phpBB Standalone Template Engine

Discussion forum for MOD Writers regarding MOD Development.
User avatar
imkingdavid
Former Team Member
Posts: 2672
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: phpBB Standalone Template Engine

Post by imkingdavid »

Hexcode wrote:Can someone tell me how to make a whileloop in it?
...the same way you would currently inside phpBB, using while() and $template->assign_block_vars().

So for instance, (i'm not using phpBB's DBAL, but rather normal mysql functions)

Code: Select all

$sql = "SELECT * FROM...........";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$template->assign_block_vars('block', array(
'VAR1' => $row['var1'],
));
}
And then you'd do the same thing as normal in the template file as well.

Code: Select all

<!-- IF .block -->
<!-- BEGIN block -->
{block.VAR1}: {block.VAR2}<BR />
<!-- END block -->
<!-- ELSE -->
I've got nothing for you.
<!-- ENDIF -->
There's how you loop. :)
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
Hexcode
Registered User
Posts: 77
Joined: Fri Apr 10, 2009 4:51 pm
Location: Cologne, Germany

Re: phpBB Standalone Template Engine

Post by Hexcode »

Thanks^^
But I already found this was :)
I don't often work with the phpBB engine, but since I can use it in my hosting script I learn it better ;)
Kjtocool
Registered User
Posts: 186
Joined: Mon Jul 19, 2004 1:09 am

Re: phpBB Standalone Template Engine

Post by Kjtocool »

Would it be possible for someone to zip up a Hello World regarding this example? Something that essentially puts together the most minimalistic set of files needed to create a page with a) title b) "Hello World" in the body using this template system?

This thread has already been immensely helpful, I just think it would be that much more so if I could download a zip file of the example and start investigating how it works. I'm not familiar with phpbb's template system, nor phpbb in general. I've never dug into the inards of phpbb, but have coded in php for years, and am very interested in learning it and possibly using it in the fashion suggested by this thread. My problem is, I tried putting together the example myself and the page comes up blank. I'm sure I'm missing something utterly simple, but without knowing how the entire system works, I'm not sure what that is!
User avatar
imkingdavid
Former Team Member
Posts: 2672
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: phpBB Standalone Template Engine

Post by imkingdavid »

Kjtocool wrote:Would it be possible for someone to zip up a Hello World regarding this example? Something that essentially puts together the most minimalistic set of files needed to create a page with a) title b) "Hello World" in the body using this template system?

This thread has already been immensely helpful, I just think it would be that much more so if I could download a zip file of the example and start investigating how it works. I'm not familiar with phpbb's template system, nor phpbb in general. I've never dug into the inards of phpbb, but have coded in php for years, and am very interested in learning it and possibly using it in the fashion suggested by this thread. My problem is, I tried putting together the example myself and the page comes up blank. I'm sure I'm missing something utterly simple, but without knowing how the entire system works, I'm not sure what that is!
Well, it's about bed time right now but if I remember this tomorrow after school I'll be happy to cook something up for you. In the meantime, I suggest reading through http://wiki.phpbb.com/Tutorial.Template_syntax to give you a general idea of how it all works. :)
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
Kjtocool
Registered User
Posts: 186
Joined: Mon Jul 19, 2004 1:09 am

Re: phpBB Standalone Template Engine

Post by Kjtocool »

I'd really appreciate that David, thanks for the help!
User avatar
imkingdavid
Former Team Member
Posts: 2672
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: phpBB Standalone Template Engine

Post by imkingdavid »

Alright, turns out I was actually the one that was missing something utterly simple, not you (assuming you were using the file I provided a few posts back, which I have now fixed, btw). I had forgotten to remove the second check for if(!defined('IN_PHPBB')) { exit; }, so it was exiting the script. Took me half an hour to realize that too.

Anyway, I set up an example here, which you can download here (zip).

All it does is output
Hello world
onto the page, but I have explained how to use each of the functions in the script. For info on how to use other template functions, either ask here, check the tutorial in the wiki that I posted in my previous post, or dig through phpBB itself.

The engine is quite powerful and has pretty much all of the functions you'll need for your site's template and it's very easy to use once you get used to it. BTW, I tried testing out the cache system and it caused blank white pages for me, and when I removed the cache folder everything worked again. If you get it working, great and let me know how. But otherwise, I guess just don't make a folder named cache in your site's root. :)

Anyway, I hope this helps a few people. :)
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
Kjtocool
Registered User
Posts: 186
Joined: Mon Jul 19, 2004 1:09 am

Re: phpBB Standalone Template Engine

Post by Kjtocool »

Thanks again for your help David. I downloaded the zip, and it's working as expected, which will make my life much easier when I start attempting to dissect it.

My original problem was likely two fold: the error in your file and using the cache folder. I'm glad the Hello World example is now available, because without your help, I would never have found either issue. I'm sure I'll run into more issues once I start attempting to use this for my own development, but until then, you've been great.
User avatar
imkingdavid
Former Team Member
Posts: 2672
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: phpBB Standalone Template Engine

Post by imkingdavid »

Kjtocool wrote:Thanks again for your help David. I downloaded the zip, and it's working as expected, which will make my life much easier when I start attempting to dissect it.

My original problem was likely two fold: the error in your file and using the cache folder. I'm glad the Hello World example is now available, because without your help, I would never have found either issue. I'm sure I'll run into more issues once I start attempting to use this for my own development, but until then, you've been great.
You're very welcome. Glad I was able to get you started. 8-)
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
Kjtocool
Registered User
Posts: 186
Joined: Mon Jul 19, 2004 1:09 am

Re: phpBB Standalone Template Engine

Post by Kjtocool »

So I started looking through the template_class.php file in your Hello World example, and a few question jumped out at me I'm hoping you (or anyone) can answer for me.


1) I see many functions, for instance set_custom_template, declaring reference to global variables like so:

Code: Select all

global $phpbb_root_path, $user;
Yet I can find no global variables in the class they could be referencing, and thus am unsure how these variables can hold any value when declared?


2) I am hoping someone is willing to explain to me the purpose and proper use of $_tpldata in the class template? From what I can gather, the variable is a multi-dimensional array which I suppose stores variables, but I couldn't discern its use.


Thanks!
User avatar
imkingdavid
Former Team Member
Posts: 2672
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: phpBB Standalone Template Engine

Post by imkingdavid »

tbh, I'm not sure on either question. All I know is that it works like it is. :?
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
ChaosBringer
Registered User
Posts: 412
Joined: Mon Apr 19, 2004 11:30 pm
Contact:

Re: phpBB Standalone Template Engine

Post by ChaosBringer »

...[removed]...
Last edited by ChaosBringer on Tue Nov 24, 2015 10:34 pm, edited 1 time in total.

01000001 01101100 01101100 00100000 01111001 01101111 01110101 01110010 00100000 01100010 01101001 01101110 01100001 01110010 01111001 00100000 01100001 01110010 01100101 00100000 01100010 01100101 01101100 01101111 01101110 01100111 00100000 01110100 01101111 00100000 01110101 01110011 00100001
User avatar
igorw
Former Team Member
Posts: 8024
Joined: Fri Dec 16, 2005 12:23 pm
Location: {postrow.POSTER_FROM}
Name: Igor Wiedler

Re: phpBB Standalone Template Engine

Post by igorw »

You may be interested it PDO, the database abstraction layer that comes with PHP5.
Igor Wiedler | area51 | GitHub | trashbin | Formerly known as evil less than three
Kjtocool
Registered User
Posts: 186
Joined: Mon Jul 19, 2004 1:09 am

Re: phpBB Standalone Template Engine

Post by Kjtocool »

Kjtocool wrote: 1) I see many functions, for instance set_custom_template, declaring reference to global variables like so:

Code: Select all

global $phpbb_root_path, $user;
Yet I can find no global variables in the class they could be referencing, and thus am unsure how these variables can hold any value when declared?
Found the answer to this: $phpbb_root_path and $user are declared in index.php, the file which then includes the class template_class.php. Thus they are declared and populated prior to being referenced. Now to figure out #2, I don't think that one will be so easy.
Kjtocool
Registered User
Posts: 186
Joined: Mon Jul 19, 2004 1:09 am

Re: phpBB Standalone Template Engine

Post by Kjtocool »

I uploaded a 'Hello World' example to my own server. This is meant to be a bit more practical of an example, and includes the following:
Features wrote: - Integration with any existing forum session
- Ability to login if not already logged in
- Login will persist should you then visit the forum, no need to login a second time
- Utilizing phpbb's powerful template engine.
I am providing this simply because this is the end I am working towards: A site utilizing this engine, which integrates with a forum powered by phpbb. To accomplish this I had to make some changes, and I have a few more planned:
Future Enhancements wrote: - Validation Page doesn't currently use layout engine. Remove page entierly, have the login redirect to itself, build code in to handle this
- Go through layout class and remove cache references as i'm not caching layouts, also remove unnecessary or unused functions
- Rename functions to fit new class name: layout (name was changed so it wouldn't conflict with the template class of phpbb)
- Currently adding common.php to index.php so that session management will work (as the example in this thread detailed. Instead, go through and find the individual classes and functions that are required so that we aren't bloating the file with extra classes, code and functions that aren't needed just to integrate a session.
If you're interested in just seeing how I modified some of the files to fit the above:

index.php

Code: Select all

<?php
    define('IN_PHPBB', true);
    
    $site_root_path = './';
    $phpbb_root_path = '../forum/';
    $phpEx = 'php';
    $user = '';
    
    include('class/layout.php');
    include($phpbb_root_path . 'common.' . $phpEx);
    
    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup(); 
    
    // Build template
    $layout = new template();
    $layout->set_custom_template('layout', 'default'); 
    $layout->assign_vars(array(
                                    'U_IS_REGISTERED' => ($user->data['is_registered']) ? true : false,
                                    'U_USERNAME' => $user->data['username']
                                   ));
    $layout->set_filenames(array(
                                    'body' => 'index_body.html'
                                   ));                                

    $layout->display('body'); 
?>
index_body.html

Code: Select all

<!-- INCLUDE header.html -->

<!-- IF U_IS_REGISTERED -->
<div>
    Welcome Back {U_USERNAME}
</div>
<!-- ELSE -->
<div>
    <form method="POST" action="validate.php">
        <p>
            Username: <input type="text" name="username" size="40"><br />
            Password: <input type="password" name="password" size="40"><br />
            <input type="submit" value="Submit" name="login">
        </p>
    </form>
</div>
<!-- ENDIF -->

<!-- INCLUDE footer.html -->
 
layout.php
- Modified class name
- Changed the name of a variable reference from $phpbb_root_path to instead reference $site_root_path. This is needed for integration of the forum files with the standalone template engine.


Final notes:
- My site is setup as follows:

/
/forum (contains the forum)
/test (contains the code above)

You will need to either match that structure, or modify the root variables accordingly. Hope someone finds this of some use.

Zip File
ChaosBringer
Registered User
Posts: 412
Joined: Mon Apr 19, 2004 11:30 pm
Contact:

Re: phpBB Standalone Template Engine

Post by ChaosBringer »

Kjtocool wrote:I uploaded a 'Hello World' example to my own server. This is meant to be a bit more practical of an example, and includes the following:
Features wrote: - Integration with any existing forum session
- Ability to login if not already logged in
- Login will persist should you then visit the forum, no need to login a second time
- Utilizing phpbb's powerful template engine.
I am providing this simply because this is the end I am working towards: A site utilizing this engine, which integrates with a forum powered by phpbb. To accomplish this I had to make some changes, and I have a few more planned:
Future Enhancements wrote: - Validation Page doesn't currently use layout engine. Remove page entierly, have the login redirect to itself, build code in to handle this
- Go through layout class and remove cache references as i'm not caching layouts, also remove unnecessary or unused functions
- Rename functions to fit new class name: layout (name was changed so it wouldn't conflict with the template class of phpbb)
- Currently adding common.php to index.php so that session management will work (as the example in this thread detailed. Instead, go through and find the individual classes and functions that are required so that we aren't bloating the file with extra classes, code and functions that aren't needed just to integrate a session.
If you're interested in just seeing how I modified some of the files to fit the above:

index.php

Code: Select all

<?php
    define('IN_PHPBB', true);
    
    $site_root_path = './';
    $phpbb_root_path = '../forum/';
    $phpEx = 'php';
    $user = '';
    
    include('class/layout.php');
    include($phpbb_root_path . 'common.' . $phpEx);
    
    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup(); 
    
    // Build template
    $layout = new template();
    $layout->set_custom_template('layout', 'default'); 
    $layout->assign_vars(array(
                                    'U_IS_REGISTERED' => ($user->data['is_registered']) ? true : false,
                                    'U_USERNAME' => $user->data['username']
                                   ));
    $layout->set_filenames(array(
                                    'body' => 'index_body.html'
                                   ));                                

    $layout->display('body'); 
?>
index_body.html

Code: Select all

<!-- INCLUDE header.html -->

<!-- IF U_IS_REGISTERED -->
<div>
    Welcome Back {U_USERNAME}
</div>
<!-- ELSE -->
<div>
    <form method="POST" action="validate.php">
        <p>
            Username: <input type="text" name="username" size="40"><br />
            Password: <input type="password" name="password" size="40"><br />
            <input type="submit" value="Submit" name="login">
        </p>
    </form>
</div>
<!-- ENDIF -->

<!-- INCLUDE footer.html -->
 
layout.php
- Modified class name
- Changed the name of a variable reference from $phpbb_root_path to instead reference $site_root_path. This is needed for integration of the forum files with the standalone template engine.


Final notes:
- My site is setup as follows:

/
/forum (contains the forum)
/test (contains the code above)

You will need to either match that structure, or modify the root variables accordingly. Hope someone finds this of some use.

Zip File
If you are doing all of this, why not just use the Custom Page Mod that is already out there that makes use of everything in phpBB??

01000001 01101100 01101100 00100000 01111001 01101111 01110101 01110010 00100000 01100010 01101001 01101110 01100001 01110010 01111001 00100000 01100001 01110010 01100101 00100000 01100010 01100101 01101100 01101111 01101110 01100111 00100000 01110100 01101111 00100000 01110101 01110011 00100001
Locked

Return to “[3.0.x] MOD Writers Discussion”