Fog Creek Software
Discussion Board




Templating systems for ASP.Net?

I was glancing over examples at www.gotdotnet.com, tying to judge ASP.Net as a platform for building web apps.

Coming from Perl background, it's natural for me to generate HTML with some templating engine, like Mason or Template Toolkit. I've looked, but found no equivalents in the ASP world. I've seen examples using XML and XSLT to do something similar, but I have trouble believing someone would want to use it for anything but small and trivial things. It's too unreadable and underpowered, compared to traditional templating systems.

But I still think I've heard somewhere that templating solutions for ASP.Net exit. Am I missing something?

Egor
Monday, July 26, 2004

I'm not exactly sure what you're looking for, but could something like Codesmith be it?:

http://www.ericjsmith.net/codesmith/default.aspx

Herbert Sitz
Monday, July 26, 2004

ASP.NET contains it's own templating engine, codebehind.

I had used perl:mason, smarty, and a comparable system for VBScript.  No such thing with ASP.NET - it's built-in.

Sassy
Monday, July 26, 2004

ASP.NET *is* a templating engine.

Chris Tavares
Monday, July 26, 2004

Well, PHP is a templating system, yet there are templating systems for it.  Go figure.

Codesmith is a code generator that uses ASPX-like syntax.  It's pretty slick.

With ASP.Net, you can use UserControls to set common headers/footers/menus, etc.  ASP.Net 2.0 introduces the MasterPages concept.  A MasterPage sets the main layout for the page and defines content areas that the pages fill with data. 

Paul Wilson wrote an implementation of MasterPages for ASP.Net 1.1 (http://authors.aspalliance.com/PaulWilson/Articles/?id=14).  MasterPages are very useful, and may be what you're looking for.

rick (techno-weenie.net)
Monday, July 26, 2004

"Codesmith is a code generator that uses ASPX-like syntax.  It's pretty slick."

Aren't all the template systems we're talking about essentially code (viz., HTML) generators?

How does Codesmith differ from the other generators we're talking about?  Can't quite get my head around it, so maybe best thing to do is to actually try to use it. . . .

But any attempt to clarify how it differs from the template systems we're talking about would be appreciated, especially since Codesmith's author himself calls Codesmith a "template-based code generator".

Herbert Sitz
Monday, July 26, 2004

Perl::Mason and Smarty are not really Code Generators.

They use regex-style parsing to replace tokens in HTML with variables from the script program.

See:
Velocity - http://jakarta.apache.org/velocity/
Freemarker- http://freemarker.sourceforge.net/
Perl::Mason - http://www.masonhq.com/
Smarty - http://smarty.php.net/
VBsTemplate - http://www.toomba.net/dld.php

and yes, see also:
JSP / PHP / ASP / ASP.NET

The template libraries just take the separation a little further,

Sassy
Monday, July 26, 2004

Sassy, you seem to be talking things you don't know shit about.  Both HTML::Mason and Smarty rely on full-blown parsers and compilers that generate Perl (or PHP) code. They don't "replace tokens" in HTML by any meaning of it.

Egor
Monday, July 26, 2004

ahh you're right Egor.

Too bad you're a prick.

Sassy
Monday, July 26, 2004

While it's tempting to start on a new platform by bringing over the techniques and best practices from another system you're familiar with, it's not always the best way to go about things.

If you want to judge ASP.NET as a development platform, then you have to learn it properly and do things using its metaphors and methodology.  Some things will carry over, but in general they are pretty different beasts and you should try to avoid shoe-horning your existing knowledge into the new environment in places it doesn't really fit. 

Otherwise, I can already predict the outcome of your trials: "ASP.NET sucks.  When I try to use it like Perl, Perl kicks its ass every time."  Well, duh, right? :) ASP.NET != Perl != <...>

On the other hand, if you just want something that lets you do things the way you've always done them in Perl, then just use Perl :)

Joe
Monday, July 26, 2004

"If you want to judge ASP.NET as a development platform, then you have to learn it properly and do things using its metaphors and methodology."

Then again, Codesmith has been named one of the "Ten Must Have Tools for .NET" in a recent MSDN article:

http://msdn.microsoft.com/msdnmag/issues/04/07/MustHaveTools/default.aspx

Just kidding, actually I mostly agree with the comment I quoted.

Though I haven't yet used Codesmith it looks like it is in fact a tool that operates in much the same way as ASP.NET templating (but which somehow extends it) so that you would likely want to learn ASP.NET built-in templating before using the Codesmith templating.  (I've been curious about Codesmith for some time now; maybe this thread will finally get me to take a look at it.)

Herbert Sitz
Monday, July 26, 2004

Joe, any differences ASP may have compared to Perl (or Python, or Java - you name it) can't take away the necessity to program HTML generation separately from application logic, and in the form of reusable components.

If ASP.NET somehow makes it unnecessary, I'd really like to know how. Because the Codebehind feature that seems to be the ASP's answer to that is critiqued by ASP people all over my Google results.

Egor
Monday, July 26, 2004

Egor, ASP.NET is very, very different from classic ASP. Who are these "ASP" people who are complaining about codebehind? Are they classic ASP people who don't get/like codebehind just because it's different? I'm not dismissing their complaints, but I'd be interested to read any such complaints myself; I'm always willing to look at a different perspective.

From where I stand, the combination of codebehind and web server controls is a great, powerful way to build websites quickly with sane architecture that doesn't dissolve into mud over time. Classic ASP didn't allow this very well at all.

Chris Tavares
Monday, July 26, 2004

Some cases are made against Codebehind here:

http://www.developer.com/net/csharp/article.php/3087791

Egor
Monday, July 26, 2004

Well, as I read that article, it's complaining about the VS.NET designer, not the codebehind model itself. Thanks for the link!

Chris Tavares
Monday, July 26, 2004

My suggestion: Create your own HttpHandler. Use HtmlTextWriter to make it easier to render your desired Html. Then you can create a base HttpHandler that all the pages on the site derive from.

I have done 2 large projects like this. They are easy to deploy, easy to maintain. You just can’t use the web designer features in the IDE. So you better know Html and CSS very well.

Gary van der Merwe
Tuesday, July 27, 2004

I recently had to go through this same adjustment.  The server side HTML controls are the ASP.NET answer to templates.  I found that it works pretty well, but when I went back to PHP after a two year absence I found that I was a lot happier with PHP and a template engine than I was with the server side controls.

Clay Dowling
Tuesday, July 27, 2004

Server-side controls are great, but they're ridiculously heavy-weight if you intend to use all the native ones. Creating tables becomes a real chore.

The power is in creating new controls that combine old ones into great time saving devices. If your site is data driven, then putting together a UI is nothing more than a visitor/factory system that throws out controls dynamically based on what it is you're looking at/editing, etc.

Brad Wilson (dotnetguy.techieswithcats.com)
Tuesday, July 27, 2004

"My suggestion: Create your own HttpHandler..."

Gary, right on.  I created a handler that parses the query string into actual c# methods and parameters using reflection. My rendering is done via XSLT.

I have a love/hate relationship with asp.net. Love the easy xCopy deployability and c# and stuff...but the web forms and widgets are just horrible to use...A real step back if you know what you're doing with HTML and state mgmt.

Apparently, M$ wanted to abstract all of the functionality so that it could have a consistent framework & terminology for both rich client forms and web. Most of us don't care about rich client forms and already understand the basics of gets, posts, session state, cookies, etc.

My message to M$. Thanks for dumbing down and abstracting all the concepts 4 me. But no thanks.

As far as a templating system, consider building web pages using XSLT. It's becoming more universal, so learning the skill will serve you well. There are more & more WYSYWIG editors for this, too. I'll just continue to use notepad.

Peter Wieselquist
Wednesday, August 25, 2004

*  Recent Topics

*  Fog Creek Home