WebTools Templates: Page 2

3. INLINE/INPERL templates: Description and reference 

  WebTools has unique capability to manage templates with build-in functions (INLINE/INPERL), also it has "xreader" module that can be used directly in your WebTools scripts. With out any doubts, "templates" are realy important part of WebTools, so this doucument intend to be comprehensive source to learn how to work with it!

   Generally INLINE/INPERL templates have exactly same functions as normal xreader has! But INLINE/INPERL templates are more comfortable and easer to use.

NOTE 1: I want to make one stipulation: INLINE and INPERL terms mean and do absolutly same things, but INPERL is used in Perl code and INLINE is used only in HTML code! From now on I will use term INLINE instead of INLINE/INPERL.

NOTE 2: There is small difference between INLINE and INPERL. Result of INLINE template will be pushed directly into HTML code, where template itself exist! From another hand INPERL return it's result into default variable $_ Please keep this in your mind!

INLINE syntax:

  
  <!--©INLINE©> inline functions </©INLINE©-->

  OR

  <!--©INPERL©> inline functions </©INPERL©-->

  <!--©INLINE©></©INLINE©--> is used to excape HTML (and repectively PERL code), so code between these "tags" will be parsed from WebTools engine.

  Supported inline functions are:

<§TEMPLATE:number_of_templates_variable:$variable:§>

<XREADER:number_of_template_in_file:template_file.jhtml:$first_param,$second_param,...>

<S©L:number_of_SQL_query:"SQL query;":used_query:row_number:col_number:should_be_printed?:S©L>

<S©LVAR:number_of_template_variable:S©L>

<MENUSELECT:$html_source:"SQL query":$ref_DB:$ref_TEMPLATE:$ref_HTML:$dbh:>

I don't like to make analogy between "normal" templates described in previuos page because thay practicaly is absolutely equal. I just think to show you an example that will help you to understand difference.

At last I forgot to introduce new feature that will be useful. This "function" include file in your perl/html file independ of it's contain (it can be perl code or html... no matter!)
INCLUDE syntax:

  <!--©INCLUDE©file.ext©-->

Note that you should not use INLINE/INPERL tag for that function!!! (For more info see example below)

To see full description of INLINE/INPERL syntax and comparison between them and "normal" templates click HERE.

4. INLINE/INPERL templates: How to use it?

All INLINE and INPERL templates are located in our pretty perl/html (as we use to refer to them: WebTools perl code) without care whether database is connected or not! WebTools will care about evry insignificant detail in this form of templates. Just watch out!

----- Please save this file as: jhtml/inline.jhtml but remove this line -----
Any information here is comment till begining separator
<©N®1®1®®©>
<BR>Are you male? <input type="radio" name="Male" value="Y" <§TEMPLATE:1§>>Yes
<input type="radio" name="Male" value="N" <§TEMPLATE:2§>>No
<input type="radio" name="Male" value="-" <§TEMPLATE:3§>>Unknown :-)

<˜©˜>
----- This is end of file. Please remove this line -----

----- Please save this file as: htmls/include.whtml but remove this line -----
$color = 'red';
----- This is end of file. Please remove this line -----


----- Please save this file as: htmls/inline.whtml but remove this line -----
<!-- PERL: Hide Perl`s script
<?perl
Header(type=>'content',val=>'text/html; charset=Windows-1251');
<!--©INCLUDE©include.whtml©--> # That will include file with color definitions!
?>
//-->
<HTML>
<HEAD>
<TITLE>INLINE Example</TITLE>
</HEAD>
<BODY TEXT="white" BGCOLOR="black" LINK="red"
VLINK="
<!--©INLINE©><§TEMPLATE:7:$color:§></©INLINE©-->">
<FONT FACE="Verdana" SIZE=2><B>
<?perl
   print "Example begin!<BR>\n";
   <!--©INPERL©><XREADER:1:inline.jhtml:></©INPERL©-->
   $source = $_; # Result is in $_ !!!
   @DB_VALUES = ("Y","N","-"); #Possible values that SQL can return!
   @TEMPLATE_NUMBERS = (1,2,3); #Number of templates in HTML
   @HTML_VALUES = ("checked",""); #Possible states of "check box" tag!
   $ref1=\@DB_VALUES; #We need references to these arrays!
   $ref2=\@TEMPLATE_NUMBERS;
   $ref3=\@HTML_VALUES;
   # $sqlq = "SELECT menuState FROM menu_table WHERE menu= 'gender';";
   $sqlq = "!Y"; # That should be SQL query but we put "!" in the begining
   # so we simulate query that select "Y" state!

   $dbh = undef; #If DB handler is invalid, WebTools will connect DB for you!
?>
</B>Also see state of check box:<BR>
<!--©INLINE©><MENUSELECT:$source:$sqlq:$ref1:$ref2:$ref3:$dbh:></©INLINE©-->
<BR> My work possition is:
<!--©INLINE©><S©L:1:"select USER from webtools_users where id=0;":1:1:1:1:S©L></©INLINE©-->
</FONT>
</BODY>
</HTML>
----- This is end of file. Please remove this line -----

To run this script please save and upload these files in your webtools directory (in jhtml and htmls), open one browser and write there follow url:

http://your_server/cgi-bin/your_webtools/process.cgi?file=inline.whtml

where: your_server is host where you keep WebTools and where you can run CGI scripts,
             your_webtools is directory where you keep WebTools files.

 I hope everything works fine, but please learn evry line of this code and try to explain for you how it works :-)

Best regards!

www.proscriptum.com

Author: Julian Lishev (julian@proscriptum.com)