473,246 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

Project Design


I am fairly new to PHP and have written an application for managing spam in
a quarantine like environment.

Now the problem has arisen that Branding will eventually come into the
picture as well as localisation.

I prefer to embed php code into the HTML segments of the page, the dynamic
PHP components having been populated by middleware classes that can take
care of all the business logic.

But now I am finding that it might be better to write classes that generate
blocks of HTML instead of having dynamic elements of PHP inside HTML.

What have other users experiences been like? Do you prefer to write
functions that generate HTML or do you prefer to have HTML blocks with PHP
in them?

Looking forward to reply's!
Rich
--
beep beep
Jul 17 '05 #1
2 1442
Richard Stride wrote:
I am fairly new to PHP and have written an application for managing spam in
a quarantine like environment.

Now the problem has arisen that Branding will eventually come into the
picture as well as localisation.

I prefer to embed php code into the HTML segments of the page, the dynamic
PHP components having been populated by middleware classes that can take
care of all the business logic.

But now I am finding that it might be better to write classes that generate
blocks of HTML instead of having dynamic elements of PHP inside HTML.

What have other users experiences been like? Do you prefer to write
functions that generate HTML or do you prefer to have HTML blocks with PHP
in them?


Neither!

I use a custom HTML template system, which allows me to write HTML
files (one for each page, or sub-section e.g. a news article template)
completely independently of the PHP code. The HTML contains
placeholders, e.g. {USER_NAME} or {HEADLINE}. I also have a switching
system, so that HTML sections can be blanked out conditionally. Might
look something like:

<DIV>
<H1>{HEADLINE}</H1>
<P>{BODY}</P>
{IS_UGLY?}<P>One paragraph.</P>{/IS_UGLY?}
{~IS_UGLY?}<P>An alternative paragraph.</P>{/~IS_UGLY?}
</DIV>

I then have a function which parses the template file, and replaces the
placeholders with strings. So I can just call something like:

parseTemplate("home.html", array("USER_NAME" => $userName,
"EMAIL_ADDRESS" => $email,
"HEADLINE" => $headline,
"BODY" => $newsBody,
"IS_UGLY?" => true));

This may seem like a lot of work to set up, and overkill, and some
might say that it's inefficient at runtime. But from a maintainability
and clarity point of view, it's perfect. There's a sharp interface
between my PHP scripts and HTML design, it's immediately obvious what
variables are going where, and I can design the HTML and PHP completely
separately. And there's no messy nesting of HTML in PHP (so no escape
characters that reduce clarity) or vice versa.

--
Oli

Jul 17 '05 #2
Richard Stride wrote:

I am fairly new to PHP and have written an application for managing spam
in a quarantine like environment.

Now the problem has arisen that Branding will eventually come into the
picture as well as localisation.

I prefer to embed php code into the HTML segments of the page, the dynamic
PHP components having been populated by middleware classes that can take
care of all the business logic.

But now I am finding that it might be better to write classes that
generate blocks of HTML instead of having dynamic elements of PHP inside
HTML.

What have other users experiences been like? Do you prefer to write
functions that generate HTML or do you prefer to have HTML blocks with PHP
in them?

Looking forward to reply's!


This has been well covered recently and there is a FAQ entry, but here is my
$.02.

The FAQ entry says it best, PHP is itself a templating system, separation of
logic and layout are accomplished by habit and practice, not by technology.

So if you look at templating systems, you will see stuff like:

<h1>{Title}</h1>

Whereas if you just assign pieces of HTML into a lot of variables, you have
this:

<h1><?=$Title?></h1>

The only difference is that in the second case you don't have to learn a new
language or parse the file.

You can also go the other way in building strings, such as this:

$HTML_BigOutput .= "<h1>".$Title."</h1>"

but I personally have found that cumbersome and problematic.

With all of that said, when we make a page "brandable" we identify the
smallest fragments of HTML that cannot be divided, assign them to
variables, and then include an HTML file, like so:

$Title = "Page Title";
$text = "This is some simple text";
include("HTML_Output.php");

....and the file HTML_Output.php looks like:

<html>
<head>
<title><?=$Title?></title>
</head>
<body>
<h1><?=$Title?></h1>
<?=$text=?>
</body>
</html>

You can then replace the HTML_Output.php file with something that has
different graphics, placement of objects and so forth.

--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: nospam | last post by:
THIS IS the DOTNETJUNKIES MESSAGE ------------------------- We're Sorry As many of you know we have recently launched SqlJunkies.com. We have overhauled our runtime and will be using it on...
1
by: athos | last post by:
Hi all, Believe you have sound experience in development, however, if we look at the whole Software Development Life Cycle (SDLC) of the project, say, 1. Project Initiation, 2. Gathering...
1
by: John Smith | last post by:
Hi, How can I get the project folder programmatically at design time? I'd like to use it in the Forms Designer during dialog design process... And another question... how can I create a custom...
8
by: Adam Clauss | last post by:
I have a folder containing many subfolders (and subfolders and....) all containing various .cs files. Is there any "easy" way to get them all added to the solution. Preferable would be that the...
3
by: John Murray | last post by:
Hi, I'm setting up a project management website, and having a bit of trouble. As part of the site, I have been asked to have a javascript dropdown menu that will open several MS Project (mpp)...
11
by: John Fly | last post by:
I'm working on a large project(from scratch). The program is essentially a data file processor, the overall view is this: A data file is read in, validated and stored in a memory structure...
3
by: Simon | last post by:
Hi there, my question is not specifically related to C++, but rather the practice around it. I've started a big project in C++ and stumbled onto a couple problems like inter-dependency, forward...
10
by: AG | last post by:
I am trying to use a ReportViewer control in a VS 2005 web application project (not Website project). When I try to create a new report (local), I can't seem to find any method to create a...
1
by: Tim | last post by:
Dear All, In my opinion, there are so many possible designs for a project, even small up to a class. How can I know which one is better? Is there any important point I should consider in the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.