[Templates-cvs] cvs commit: Template2/docsrc/src/FAQ FAQ.tt2

cvs@template-toolkit.org cvs@template-toolkit.org


cvs         06/02/01 10:54:36

  Modified:    docsrc/src/FAQ FAQ.tt2
  Log:
  * added question on template/component and modification time
  
  Revision  Changes    Path
  1.11      +65 -9     Template2/docsrc/src/FAQ/FAQ.tt2
  
  Index: FAQ.tt2
  ===================================================================
  RCS file: /template-toolkit/Template2/docsrc/src/FAQ/FAQ.tt2,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- FAQ.tt2	2004/01/30 18:01:08	1.10
  +++ FAQ.tt2	2006/02/01 10:54:35	1.11
  @@ -180,6 +180,62 @@
   
   =head1 Miscellaneous
   
  +=head2 How can I find out the name of the main template being processed?
  +
  +The C<template> variable contains a reference to the
  +Template::Document object for the main template you're processing
  +(i.e. the one provided as the first argument to the Template process()
  +method).  The C<name> method returns its name.
  +
  +    [% template.name %]     # e.g. index.html
  +
  +=head2 How can I find out the name of the current template being processed?
  +
  +The C<template> variable always references the I<main> template being processed.
  +So even if you call [% INCLUDE header %], and that calls [% INCLUDE menu %],
  +the C<template> variable will be unchanged.
  +
  +index.html
  +    [% template.name  %]     # index.html
  +    [% INCLUDE header %]
  +
  +header:
  +    [% template.name  %]     # index.html
  +    [% INCLUDE menu   %]
  +
  +menu:
  +    [% template.name  %]     # index.html
  +
  +In constrast, the C<component> variable always references the I<current>
  +template being processed.  
  +
  +index.html
  +    [% component.name %]     # index.html
  +    [% INCLUDE header %]
  +
  +header:
  +    [% component.name %]     # header
  +    [% INCLUDE menu   %]
  +
  +menu:
  +    [% component.name  %]     # menu
  +
  +=head2 How do I print the modification time of the template or component?
  +
  +The C<template> and C<component> variables reference the main template
  +and the current template being processed (see previous questions).
  +The C<modtime> method returns the modification time of the
  +corresponding template file as a number of seconds since the Unix
  +epoch (00:00:00 GMT 1st January 1970).
  +
  +This number doesn't mean much to anyone (except perhaps serious Unix
  +geeks) so you'll probably want to use the Date plugin to format it for
  +human consumption.
  +
  +    [% USE Date %]
  +
  +    [% template.name %] last modified [% Date.format(template.modtime) %]
  +
   =head2 How can I configure variables on a per-request basis?
   
   One easy way to acheive this is to define a single PRE_PROCESS template which
  @@ -214,13 +270,13 @@
   
   	    # define various other style variables....
               col = {
  -		back => '#ffffff'
  -		text => '#000000'
  -		# ...etc...
  +    		back => '#ffffff'
  +	    	text => '#000000'
  +		    # ...etc...
   	    }
   
   	    logo = {
  -		# ...etc...
  +		    # ...etc...
   	    }
   
   	    # ...etc...
  @@ -243,11 +299,11 @@
   config/section/info:
   
       [%  section = {
  -	    name   = section  # save 'section' var as 'section.name'
  -	    title  = 'Information'
  -	    menu   = [ ... ]
  -	    # ...etc...
  -	}
  +	        name   = section  # save 'section' var as 'section.name'
  +	        title  = 'Information'
  +	        menu   = [ ... ]
  +	        # ...etc...
  +	    }
       %]
   
   This illustrates the basic principal but you can extend it to perform