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