Re: Re: Question about template systems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Robert Cummings wrote:
On Wed, 2009-03-04 at 18:01 -0800, Michael A. Peters wrote:
Robert Cummings wrote:
On Wed, 2009-03-04 at 15:21 -0800, Michael A. Peters wrote:
Robert Cummings wrote:

To punt what is repeated over and over during runtime to a single
compilation phase when building the template target. To simplify the use
of parameters so that they can be used in arbitrary order with default
values. To allow for the encapsulation of complex content in tag format
that benefits from building at compile time and from being encapsulated
in custom tags that integrate well with the rest of the HTML body.
I can't speak to those (and I have no opinion on template systems having never used any of them.

To
remove the necessaity of constantly moving in and out of PHP tags.
php does not require that you constantly move in and out of PHP tags.
There's at least one and possibly several pure php solutions that allow one to never write a line of html but get beautiful dynamic html output.
It doesn't require, but if you're not moving between them, then you're
probably echoing your HTML, and that can be a maintenance nightmare.
echoing html involves mixing html and php.
Using an XML class (like DOMDocument) to build the document does not.

So you punt the entire rendering of the HTML content to run-time
execution one node at a time?

Cheers,
Rob.

This is what I do.
I create the nodes as needed and add them to the parent nodes when I'm done with them - and when the document is finished, add the various content nodes to the body node, body/head nodes to html node, and then use saveXML(); to get the output as x(ht)ml to send to the browser.

If that's what you described then yes. Otherwise, then no - it's not.

some example, IE to build my form -

$xmlForm = $myxhtml->createElement("form");
$xmlForm->setAttribute("id","records");
$xmlForm->setAttribute("method","post");
if ($multipart > 0) {
   $xmlForm->setAttribute("enctype","multipart/form-data");
   }
$xmlForm->setAttribute("action",$formaction);
$xmlForm->setAttribute("onsubmit",$onsubmit);
$hiddenDiv = $myxhtml->createElement("div");
$hiddenDiv->setAttribute("id","hidden_inputs");
$hinput=hiddenInput($myxhtml,"coord_pref",$coord_pref);
$hinput->setAttribute("id","coord_pref");
$hiddenDiv->appendChild($hinput);
$hinput=hiddenInput($myxhtml,"alt_pref",$alt_pref);
$hiddenDiv->appendChild($hinput);
$hinput=hiddenInput($myxhtml,"temp_pref",$temp_pref);
$hiddenDiv->appendChild($hinput);

// etc ..

if(isset($imgref)) {
   $hinput=hiddenInput($myxhtml,"imgref",$imgref);
   $hiddenDiv->appendChild($hinput);
   $hasimage=1;
   }

if ($museum == 1) {
   if (isset($validarray['museum'])) {
      require('xml_record_museum.inc');
      } else {
      $hinput=hiddenInput($myxhtml,"museumid",$rcd_musid);
      $hinput->setAttribute("id","museumid");
      $hiddenDiv->appendChild($hinput);
      $hinput=hiddenInput($myxhtml,"museum_name",$rcd_musnum);
      $hinput->setAttribute("id","museum_name");
      $hiddenDiv->appendChild($hinput);
      }
   }
if ($editrecord == 1) {
   $hinput=hiddenInput($myxhtml,"recordid",$record);
   $hiddenDiv->appendChild($hinput);
   }
if (isset($validarray['species'])) {
   require('xml_record_species.inc');
   } else {
   $hinput=hiddenInput($myxhtml,"herpid",$rcd_species);
   $hinput->setAttribute("id","herpid");
   $hiddenDiv->appendChild($hinput);
   }

...

$xmlForm->appendChild($hiddenDiv);
$submitDiv = $myxhtml->createElement("div");
$submitDiv->setAttribute("id","submitdiv");
$submitDiv->setAttribute("class","formFloat");

$submitInput = $myxhtml->createElement("input");
$submitInput->setAttribute("type","submit");
$submitInput->setAttribute("id","submit");
$submitInput->setAttribute("name","submit");
$submitInput->setAttribute("value",$submit_val);
$submitDiv->appendChild($submitInput);

$xmlForm->appendChild($submitDiv);
$contentDiv->appendChild($xmlForm);

The various requires are files that create various parts of the form. They are in individual separate files because some of them are used in other forms and I don't like to have replicated code that is functionally equivalent.

hiddenInput is a simple function I wrote that returns an input node of type hidden - which I can (when needed, IE if I want to add an id tag for javascript hook) I can continue to modify.

function hiddenInput($document,$name,$value) {
   $input = $document->createElement("input");
   $input->setAttribute("type","hidden");
   $input->setAttribute("name",$name);
   $input->setAttribute("value",$value);
   return($input);
   }

Does that answer your question?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux