|
Posted by kenoli on 05/30/06 02:57
In a very general sense, but considering more subtleties. In a system
where these elements stay the same on every page and where php and html
are isolated from each other, this works and is pretty straight
forward.
What I am looking at are pages that load various forms, wich are
largely html but which contain php items lilke option lists drawn from
a lookup table or form fields filled in from a php/mysql generated
array or "while loops" populating an html form.
When all of this html code is included interspersed with php code, the
file gets pretty messy and, since the various kinds of code are
interspersed, it is hard to separate it out the function from the
content. I think there are some sphisticated ways to do this using
placeholders and the like.
In addition, it is convenient to be able to make changes to the html or
associate databases and the html forms that relate to them to in a way
thatdoesn't affect the core php code or even better, have php code that
can adpt to these changes.
It's the old saw about separating form from content. It's possible, of
course to create functions that contain entire sections of the code and
call the functions. but this doesn't separate form and content; it
simply modularizes the script. I'm looking for womething a bit more
elegant.
As an example, heredoc is a useful tool for including large sections of
html interspersed with php elements as it will interpret them just as a
print() statement will. this makes it possible to separate out large
blocks of html and then insert them into php code where needed. I
should even be possible to write code that can parse the data submitted
by the form and adapt itself to what it gets, even modify fields in a
database to conform to new form data.
What I have learned in this exchange is the need to put php tags in my
included files. that solved my immediate problem. I've got lots of
other questions like the value of calling functions from within
template files or in the mother file, how to separate out html into an
included file when using a loop to populate certain html elements, and
how to make code flexible enough to adapt to changes in html input.
Thanks,
--Kenoli
[Back to original message]
|