Better template.php ? [message #18057] |
Mon, 13 November 2006 22:52  |
Eclipse User |
|
|
|
So ... the basic template for generating pages in projects using this
php Phoenix magic looks like this:
--- snip -----
<?php ## The "require" magic is "off-screen"
# Begin: page-specific settings. Change these.
$pageTitle = "Sample Phoenix web page using the new templates";
$pageKeywords = "Type, page, keywords, here";
$pageAuthor = "Type your name here";
# Add page-specific Nav bars here
# $Nav->addCustomNav("My Link", "mypage.php", "_self", 3);
# $Nav->addCustomNav("Google", "http://www.google.com/", "_blank", 3);
# Paste your HTML content between the EOHTML markers!
$html = <<<EOHTML
html goes here.
EOHTML;
# Generate the web page
$App->generatePage($theme, $Menu, $Nav, $pageAuthor, $pageKeywords,
$pageTitle, $html);
?>
--- snip -----
I am not very familiar with PHP but the $html = <<< EOHTML line is
really making the HTML content be buried in the PHP code. This is bad
for 2 reasons:
1) I can't use simple PHP include(file) directive to include content
that I may need in more then 1 place.
2) The PHPEclipse editor syntax highlighting is completely shot for the
HTML that is buried in the PHP code.
I read a little about output buffering in PHP and this template seems
more logical to me and fixes these 2 issues.
Changes have the <-- comment next to them
--- snip -----
<?php ## The require magic is "off-screen"
ob_start(); # <-- turns on buffering
# Begin: page-specific settings. Change these.
$pageTitle = "Sample Phoenix web page using the new templates";
$pageKeywords = "Type, page, keywords, here";
$pageAuthor = "Type your name here";
# Add page-specific Nav bars here
# $Nav->addCustomNav("My Link", "mypage.php", "_self", 3);
# $Nav->addCustomNav("Google", "http://www.google.com/", "_blank", 3);
# <-- now close the PHP code section
?>
HTML goes here. PHPEclipse will nicely hilite the syntax because now it
knows that it is in the "html" area and give me HTML templates as I need
them via code assist.
You can do also things like <?= $pageAuthor ?> which are PHP escapes for
expressions.
You can also include pages such as ...
<?php include("some.page.html") ?>
<?php
# Generate the web page.
# <-- ob_get_clean() will get the currently produced output which
# <-- sits in the buffer and erase the buffer so that
# <-- App->generatePage() can do the chrome around the page content
#
$App->generatePage($theme, $Menu, $Nav, $pageAuthor, $pageKeywords,
$pageTitle, ob_get_clean() );
?>
--- snip -----
This is working locally, on local.eclipe.org installation, and I presume
that it should work on Eclipse.org once checked in. However, there may
be some php configuration parameters that may not be set in the same way.
Anything that I am missing ?
-michal
|
|
|
|
|
|
Re: Better template.php ? [message #18644 is a reply to message #18069] |
Tue, 14 November 2006 13:29  |
Eclipse User |
|
|
|
Sounds good.
-m
Bjorn Freeman-Benson wrote:
> That is the way I write pages for the eclipse.org website. See for
> example: /projects/europa.php
> The only additional thing I use is:
>
> $html = ob_get_contents();
> ob_end_clean();
> $App->generatePage( ..., $html, ... );
>
> The ob_end_clean allows further code to write to the output stream
> normally. See http://us3.php.net/ob_get_contents
>
> Michal Chmielewski wrote:
>> I am not very familiar with PHP but the $html = <<< EOHTML line is
>> really making the HTML content be buried in the PHP code.
> > ...
>> I read a little about output buffering in PHP and this template seems
>> more logical to me and fixes these 2 issues.
>> Anything that I am missing ?
|
|
|
Re: Better template.php ? [message #570105 is a reply to message #18057] |
Tue, 14 November 2006 10:56  |
Eclipse User |
|
|
|
That is the way I write pages for the eclipse.org website. See for
example: /projects/europa.php
The only additional thing I use is:
$html = ob_get_contents();
ob_end_clean();
$App->generatePage( ..., $html, ... );
The ob_end_clean allows further code to write to the output stream
normally. See http://us3.php.net/ob_get_contents
Michal Chmielewski wrote:
> I am not very familiar with PHP but the $html = <<< EOHTML line is
> really making the HTML content be buried in the PHP code.
> ...
> I read a little about output buffering in PHP and this template seems
> more logical to me and fixes these 2 issues.
> Anything that I am missing ?
|
|
|
Re: Better template.php ? [message #570119 is a reply to message #18069] |
Tue, 14 November 2006 12:19  |
Eclipse Webmaster Messages: 607353 Registered: July 2009 |
Senior Member |
|
|
Indeed, Bjorn's use of the output buffer makes a much cleaner (and
better) implementation. Most of our pages use it, but I have yet to
update the templates.
D.
Bjorn Freeman-Benson wrote:
> That is the way I write pages for the eclipse.org website. See for
> example: /projects/europa.php
> The only additional thing I use is:
>
> $html = ob_get_contents();
> ob_end_clean();
> $App->generatePage( ..., $html, ... );
>
> The ob_end_clean allows further code to write to the output stream
> normally. See http://us3.php.net/ob_get_contents
>
> Michal Chmielewski wrote:
>> I am not very familiar with PHP but the $html = <<< EOHTML line is
>> really making the HTML content be buried in the PHP code.
> > ...
>> I read a little about output buffering in PHP and this template seems
>> more logical to me and fixes these 2 issues.
>> Anything that I am missing ?
|
|
|
Re: Better template.php ? [message #581087 is a reply to message #18081] |
Tue, 14 November 2006 12:24  |
Eclipse Webmaster Messages: 607353 Registered: July 2009 |
Senior Member |
|
|
Actually, most of the newer pages I create are set up for
multi-language/localized content:
template.php:
-- snip --
# Place your html content in a file called content/en_template.php
include($App->getLocalizedContentFilename());
# Generate the web page
$App->generatePage(...)
--snip--
Where all my HTML content lies in
content/[en|fr|de|etc...]_template.php, allowing for localized content.
D.
Denis Roy wrote:
> Indeed, Bjorn's use of the output buffer makes a much cleaner (and
> better) implementation. Most of our pages use it, but I have yet to
> update the templates.
>
> D.
>
>
>
> Bjorn Freeman-Benson wrote:
>> That is the way I write pages for the eclipse.org website. See for
>> example: /projects/europa.php
>> The only additional thing I use is:
>>
>> $html = ob_get_contents();
>> ob_end_clean();
>> $App->generatePage( ..., $html, ... );
>>
>> The ob_end_clean allows further code to write to the output stream
>> normally. See http://us3.php.net/ob_get_contents
>>
>> Michal Chmielewski wrote:
>>> I am not very familiar with PHP but the $html = <<< EOHTML line is
>>> really making the HTML content be buried in the PHP code.
>> > ...
>>> I read a little about output buffering in PHP and this template seems
>>> more logical to me and fixes these 2 issues.
>>> Anything that I am missing ?
|
|
|
Re: Better template.php ? [message #581101 is a reply to message #18069] |
Tue, 14 November 2006 13:29  |
Eclipse User |
|
|
|
Sounds good.
-m
Bjorn Freeman-Benson wrote:
> That is the way I write pages for the eclipse.org website. See for
> example: /projects/europa.php
> The only additional thing I use is:
>
> $html = ob_get_contents();
> ob_end_clean();
> $App->generatePage( ..., $html, ... );
>
> The ob_end_clean allows further code to write to the output stream
> normally. See http://us3.php.net/ob_get_contents
>
> Michal Chmielewski wrote:
>> I am not very familiar with PHP but the $html = <<< EOHTML line is
>> really making the HTML content be buried in the PHP code.
> > ...
>> I read a little about output buffering in PHP and this template seems
>> more logical to me and fixes these 2 issues.
>> Anything that I am missing ?
|
|
|
Powered by
FUDForum. Page generated in 0.11238 seconds