ASP Application Template adoption

Source: Internet
Author: User

When ASP is a beginner, the program can barely be written. However, every time a website page is revised, all source programs will be transplanted. The amount of manpower and energy it consumes is countless, and even the loss is not worth the candle.

Therefore, I dreamed that the code of a large program would be replaced by a few simple characters, so as long as the page is designed to insert this function, it will be OK. In fact, this is also simple. You only need to make the program code that implements this function into a subroutine, and then call the home page.

Many times, in blog China, you may choose many templates or even design them by yourself; or the webmasters who use the pig Feifei BLOG have changed their sites not nearly the same ...... All of these are attributed to ASP's use of the template function.

Now, let's take a look at the template and analyze it to feed your friends.

First, if the template needs to be modified online, the database should be used to save the template code.

The so-called template is the standard HTML code designed to be completed, which requiresFunctions implemented by the programWill adoptSpecial string. However, these special strings must be compiled into corresponding functions during display.

1. design the database testmb. mdb
Create a table moban: Field m_id (automatic number, primary keyword); field m_html (Remarks type)

2. Assume that the content code of the first template is

Copy the following code to the m_html field.

<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> testmb </title>
</Head>
<Body leftmargin = "0" topmargin = "0">
<Table width = "100%" height = "100%" border = "0" cellpadding = "5" cellspacing = "2">
<Tr align = "right" bgcolor = "# CCCCCC">
<Td height = "20" colspan = "2"> $ cntop $ </td>
</Tr>
<Tr valign = "top">
<Td width = "25%" bgcolor = "# e5e5e5"> $ cnleft $ </td>
<Td width = "74%" bgcolor = "# f3f3f3"> $ cnright $ </td>
</Tr>
</Table>
</Body>
</Html>

Note $ cntop $, $ cnleft $, and $ cnright $. They will implement certain program functions.

3. Create 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 file lib. asp required for special String Conversion

The main function of this file is to make ASP programs that implement certain functions into word programs for convenient calls.

<%
Dim topcode
Sub cntop ()
Topcode = "the current 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 special strings.

<! -- # 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
%>

This page is mainly used to display the template code and convert the special code into the corresponding subroutine function.

At this point, the ASP template function is basically complete, and the rest is: create a program page with the template editing function, change the library file to your desired 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.