RE: [PHP Template] load template from string var

From: Date: Tue, 14 Mar 2000 00:54:31 +0000
Subject: RE: [PHP Template] load template from string var
Groups: php.template 
Request: Send a blank email to php-template+get-311@lists.php.net to get a copy of this message
I agree completely that this would be useful. I'm using my own home grown template system right now that allows loading of the template via a variable and I would say that this is a must. Besides loading from a database one of the things that this allows is that I can load a different template with the tmpl_fetch() of an already loaded template. I have a loop that loads a list of templates out of a database and each pass through the loop I call a specialized function that knows how to work with each specific template. The first template in the loop is my generic template that pretty much every page on the entire site uses. This template contains things like the main site navigation, copyright footer, etc. Then the rest of the templates are loaded for the features that are specific to a single page. The result of each template is passed into the load of the next template. This way template 2 can assign values to something in template 1, like the page title. Here is an example of what I mean: 1) Call the generic_function() passing the path of the generic_template.tpl as a parameter. The generic function does the tmpl_load() and tmpl_assign() for the generic_template.tpl. 2) The generic_function() returns the parsed results of the generic_template.tpl into a variable called $Holding 3) Call specific_function1() passing in the path of a specific_template1.tpl and $Holding as parameters. specific_function1() does the tmpl_load() and tmpl_assign() on _both_ the specific_template1.tpl and the $Holding variable. The $Holding variable has tags for { PAGE_TITLE } and rather than having generic_function() assign the page title, specific_function1() does the assignment. There is a tag in the generic_template.tpl called { MAIN_BODY } that is assigned the contents of specific_template1.tpl. 4) The specific_function1() returns the combined result of generic_template.tpl and specific_template1.tpl into the $Holding variable, replacing whatever it contained before. This loop can go on and on loading as many templates as needed to build the page. Hope I explained this reasonably well. If not I can post some actual code. My two cents, Jonathan jonathan@caedic.com -----Original Message----- From: Jeremiah Bellomy [mailto:jeremiah@emphasys.net] Sent: Monday, March 13, 2000 4:28 PM To: php-template@lists.php.net Subject: [PHP Template] load template from string var This may already be possible with the current API but I couldn't tell for sure from the spec file, so here goes: I just wanted to be sure that it's possible to load a template from the contents of a PHP variable as well as from files. This allows for the possibility of storing templates in a database so that for example, I could load $my_template from the database and then make it a template with something like: tmpl_load_from_var(resource tmpl, string varname) Loads a template from the contents of a string. tmpl_load_from_var('my_template.tpl', $my_template); So, is this possible by some other means currently defined in the spec? -- Jeremiah -- PHP Template Engine Mailing List Current engine specification can be found at: http://va.php.net/~andrei/tpl-engine-spec.txt To unsubscribe, e-mail: php-template-unsubscribe@lists.php.net

« previous php.template (#311) next »