What's the difference between a template and a script? |
<TABLE>
<% SCAN
Response.Write( '<TR><TD>' + Field_1 + '</TD><TD>' + Field_2 + '</TD></TR>' )
ENDSCAN
%>
</TABLE>
Notice how, once in the code, you have to manually produce the HTML via Response.Write. Now look at the script version:
<TABLE>
<% SCAN %>
<TR>
<TD><%=Field_1%></TD>
<TD><%=Field_2%></TD>
</TR>
<% ENDSCAN %>
</TABLE>
This is much more like true HTML. In fact you could easily imagine laying out the table with a visual editor, and then just inserting the SCAN loop.
You can do anything with a script that you can do with a template, and much more. However, non-compiled scripts tend to run a lot slower than templates because they are created and then executed on the fly through Fox interpreter. For better performance of scripts you can compile scripts into native VFP code, but at that point you loose the ability to edit files without recompiling.
The syntax for templates and scripts is similar, so it's easy to switch between the two both from the calling end as well as from the script end.
For most applications I write I use templates with occasional scripts if the logic requires complex conditional or looping structures. Your preferences may vary.
Last Updated: 02/25/00