Static dynamic pages in Asp.net: differences between include and parse

Source: Internet
Author: User

Static dynamic pages in Asp.net: differences between include and parse
Static dynamic pages in Asp.net: differences between include and parse

# Include is to include other templates in the template, such as the website header, tail, and advertisement template. When the content is the same, you can create a separate template for reference everywhere.

The velocity template uses the Nvelocity variable $ body. The $ body variable can still be used in the template, but the # include variable cannot be used, and the related Nvelocity elements (# foreach, # if) cannot work, it can only be output as is, so # parse> # stored ed.

 

C # code

Using System; using System. Collections. Generic; using System. Linq; using System. Web; using NVelocity. App; using NVelocity. Runtime; namespace czbk {////// Summary of Test ///Public class Test: IHttpHandler {public void ProcessRequest (HttpContext context) {string show = I tested the difference between include and parse; context. response. contentType = text/html; VelocityEngine vltEngine = new VelocityEngine (); vltEngine. setProperty (RuntimeConstants. RESOURCE_LOADER, file); vltEngine. setProperty (RuntimeConstants. FILE_RESOURCE_LOADER_PATH, System. web. hosting. hostingEnvironment. mapPath (~ /); // The vltEngine folder where the template file is located. init (); VelocityContext vltContext = new VelocityContext (); vltContext. put (show, show); Template vltTemplate = vltEngine.GetTemplate(self.htm); System. IO. stringWriter vltWriter = new System. IO. stringWriter (); vltTemplate. merge (vltContext, vltWriter); string html = vltWriter. getStringBuilder (). toString (); context. response. write (html) ;}public bool IsReusable {get {return false ;}}}}

Other public html webpage

I use include or parse to test: $ show

 

Use the include's self.html page

 Include(others.htm) 

========== Gorgeous split line ========================


Effect

 

Use the self. hrml page of parse

 Extends parse(others.htm) 

========== Gorgeous split line ========================

 

Effect

 

 

 

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.