Better template.php ? [message #18057] |
Tue, 14 November 2006 03:52 |
Michal Chmielewski Messages: 58 Registered: July 2009 |
Member |
|
|
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
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04661 seconds