ASP Application Template Adoption

Source: Internet
Author: User
Tags functions implement include
templates | Templates Beginner ASP, the program is able to write out, but if each site page of the revision, all the source program will carry out a transplant operation. To this end, the human energy consumed countless, or even inadvertently gains, naught.

So, dream of so large section of the program code into a few simple characters instead, so as long as the design of the page to insert the function OK. In fact, this is also simple, you need to implement the function of the program code into a subroutine, and then the home page call on it.

Many times, in the blog China, you will choose to a lot of templates, even the possibility to design their own, or the use of Pig flying blog of the major webmaster will change their site is not nearly the same ... All of these are attributed to the ASP's use of template functionality.

Then I jiehuaxianfo, the template to analyze, to feed friends.

First, the template needs to be modified online, you should use the database to save the template code

The so-called template, is the design of the standard HTML code completion, which needs to be implemented by the program of the functional parts will be replaced by a special string. However, these special strings need to be compiled into corresponding functions at the time of display.

1, Design Database Testmb.mdb
New Table Moban: Field m_id (AutoNumber, primary key); Field m_html (Memo type)

2, assuming that the first template content code

Copy the following code into the M_html field


<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>testmb</title>
<body leftmargin= "0" topmargin= "0" >
<table width= "100%" height= "100%" border= "0" cellpadding= "5" cellspacing= "2" >
<tr align= "Right" bgcolor= "#CCCCCC" >
&LT;TD height= colspan= "2" > $cntop $</td>
</tr>
&LT;TR valign= "Top" >
&LT;TD width= "25%" bgcolor= "#e5e5e5" > $cnleft $</td>
&LT;TD width= "74%" bgcolor= "#f3f3f3" > $cnright $</td>
</tr>
</table>
</body>




Note that $cntop$, $cnleft $, $cnright $, they are going to implement some specific program functionality

3, establish the database connection file conn.asp



<%
Set conn= Server.CreateObject ("ADODB.") Connection ")
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" &server.mappath ("Testmb.mdb")
Conn. Open ConnStr
%>




4, create the library files required for special string conversions lib.asp

The main role of the file is to implement certain functions of the ASP program to make Word program to facilitate the invocation.



<%
Dim Topcode
Sub Cntop ()
Topcode= "Now Time is:"
Topcode=topcode&now ()
End Sub

Dim leftcode,i
Sub Cnleft ()
For i = 1 to 5
leftcode=leftcode& "<p>cnbruce.com"
Next
End Sub

Dim Rightcode
Sub Cnright ()
For i = 1 to 9
rightcode=rightcode& "Next
End Sub
%>




5, finally, call the template code in the database to convert the special string.



<!--#include file= "conn.asp"-->
<!--#include file= "lib.asp"-->
<%
Sql= "SELECT * from Moban where m_id=1"
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open sql,conn,1,1
Mb_code=rs ("m_html")
Rs.close
Set rs=nothing

Cntop ()
Mb_code=replace (Mb_code, "$cntop $", Topcode)
Cnleft ()
Mb_code=replace (Mb_code, "$cnleft $", Leftcode)
Cnright ()
Mb_code=replace (Mb_code, "$cnright $", Rightcode)

Response.Write Mb_code
%>




The main purpose of the page is to display the template code and to turn the special code into a relative subroutine feature.

At this point, the ASP's template function is basically completed, the rest is: to create a template with the function of editing the program page, the library file changes to their own needs of the program function ...



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.