Designing a templating system

来源:http://www.imcoder.org/architecture/187178.htm

 

Q:

Hi,

I am in the process of designing an ecommerce store and the client would like to offer a "white label" solution so that their affilaites can run their own stores, populated form a central database.

We need the ability for affiliates to design their own "templates" and have the application consume them and herge with the data at runtime. We have tried doing this in the past using regular expressions but it was incredibly slow.

Ideally , the user would be able to upload HTML templates to a dabase which would look a bit like this...

 

<html>
  <head>
    <title>Ecommerce Example</title>
  </head>
  <body>
    <div ID="Header">Header Goes Here</div>

    <ECO:Products Show="20">
      <ECO:ItemTemplate>
       
        <div><b><%= Product.Title %></b> - <%= Product.Price %></div>
        <p><%= Product.Summary %></p>

        <a href="<%= Product.URL %>">More Info</a> | <a href=""<%= Product.AddURL %>">Add To Cart</a>
       
      </ECO:ItemTemplate>
    </ECO:Products>
   
    <div ID="Footer">Footer Goes Here</div>
  </body>
</html>

 

Obviously there would be many parts of the page that need database content, including the category menus, best sellers, mini-basket etc so they would be big pages and it would need to be very quick.

The best example I have seen of somebody doing soemthing like this is here - http://www.liquidmarkup.org/ - They even seem to have implemented looping and branching constructs !

Anyway, I have a vague idea where to start but I'm slightly out of my depth and wondered if anyone had done this before, or come across a commercially available solution to this ?

Any help would really be appreciated.

Jon 

A:

 Am I the only person that has tried doing this ?

Jon 

A:The best solution for this would be to use XSL.
A:

 OK, I've done a little bit more digging.

 XSLT looks like a possible solution but isn't particularly easy to write.

I don't have the technical knowledge to write something that will parse templates so writing my own language like Liquid Markup is not going to happen. 

I've been looking into the new MVC engine and it looks like it may be a possibility. I don't want my users to have to write aspx templates as that kind of defeats the point so I've been looking into things like Nvelicity, Brail and StringTemplate. It's all ver confusing though so any advice would really help from people who have had to do this before.

 
Jon
 

A:

Jon,

Did you ever come up with a solution for this (or does anyone have some real input)?

I need to do something like this too.

 Thanks

TIM

A:

 Hi,

i have created a simular system, i used png semi transparent image to do the layer presentation "a sort of dark black rounded panel at Opacity 65%-70%" , and simply change the background based on the customer, it is very cute, professional finish and very re-usable, but one thing is that to obtain full performance with UI fonctionnality you need FireFox, because Javascript Stuff on IE is slower than FF.

And during the production, i was very happy to be able to change the atmosphere every week!

A:

 

Hi Jon,

Although disimilar to the Ruby (as suggested), is dependent on two elements i.e. that of UI and behaviour. A templating system can be easily built in asp.net for function such as storefront, however you will still need to provide a rich set of library for user to extend each element of the system, rather then being able to modify its UI.

A few examples I can point out are here

http://www.devx.com/dotnet/Article/18011 (control approach)

 http://msdn.microsoft.com/msdnmag/issues/02/01/cutting/ (using templates in the actual controls you can change things dynamically..a bit difficult but good approach)

http://weblogs.asp.net/scottgu/archive/2006/06/04/Supporting-Templates-with-ASP.NET-User-Controls.aspx

http://www.devarticles.com/c/a/ASP.NET/Easy-ASP.NET-Page-Templates/1/

http://www.csharphelp.com/archives2/archive383.html (a general idea)

http://aspalliance.com/articleViewer.aspx?aId=91&pId=

or simply design something similar to these http://msdn2.microsoft.com/en-us/asp.net/aa336613.aspx

posted @ 2008-08-13 14:20  KK in cnblog  阅读(216)  评论(0编辑  收藏  举报