ASP, Program But 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.
So, dreaming of such a large programCodeIt becomes a few simple characters to replace, so as long as the page is designed to insert this function 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 subDim 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 & "<HR color =" & I & ">" 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 = nothingCntop () 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 ......