shahine.com/omar/

homepage | Send mail to the author(s) contact

yet another Microsoft blogger

# Tuesday, December 16, 2003

FormatPage macro in dasBlog

Just today I discovered how to use the FormatPage functionality in dasBlog. This functionality allows you to take a regular plain html file and have it rendered in your site using existing templates etc.

Coupled with URL Rewriting you can create your own custom URLs for these pages. Say for instance that I wish to create a page for some software projects I'm working on, I don't want create a blog post for this because I want it to be permanant and static etc. So I create a simple HTML file and name it:

somefile.format.html

This file should just contain the HTML that would normaly between the tag. Note that the file name must end in .format.html or none of this will work.

You then place this file anywhere in your blog. I like to keep things in my /content folder so I create a new folder called /projects in /content and place the file in there. The path on the server is now:

/content/projects/somefile.format.html

To get to this page in dasBlog I simply type:

http://www.shahine.com/omar/FormatPage.aspx?path=content/projects/somefile.format.html

However, I don't like the way this URL looks. So to address this I go into my Web.Config file and find the section and create a new URL mapper expression.

The following expression:

<add matchExpression=
"(?&lt;basedir&gt;.*?)/Projects\.aspx\?=(?&lt;value&gt;.+)"
mapTo="{basedir}/FormatPage.aspx?path=content/projects/{value}.format.html" />

intercepts all requests to:

http://www.shahine.com/omar/Projects.aspx?=somefile

to

http://www.shahine.com/omar/FormatPage.aspx?path=content/projects/somefile.format.html

and shows the top URL to the user. Basically Projecs.aspx is a non existant page, and dasBlog is magically loading the content in somefile.format.html and displaying it to the user.

Now I can create a number of pages in my new /content/projects folder and I can use the same URL for all of them. I would simply change somefile to whatever the name of the *.format.html file prefix is.

 

Tuesday, December 16, 2003 9:50:18 PM (Pacific Standard Time, UTC-08:00)
That's exactly how I am serving up my project and article pages on DevHawk. I'm thinking story support could just be the ability to write these pages + a URL mapping.
Tuesday, December 16, 2003 10:38:00 PM (Pacific Standard Time, UTC-08:00)
Well, I like the idea of doing the URL rewriting, but I still think it would be nice to have them in the xml files. this will make 1) moving to the database easier, and 2) searching and stuff as well as pingbacks, trackbacks, and referrals work. We'd lose all that with the method above.

You know, with all the Photo work I'm doing (I'm almost done with the backend work), it would be almost trivial add the story support to all the necessary places (classes, DataManager, Macros) etc. I've already done all the work for Pictures.
Omar Shahine
Wednesday, December 17, 2003 1:40:09 AM (Pacific Standard Time, UTC-08:00)
Excellent post. Thanks for sharing that with us. I was wondering how I could do stories/articles like this. Thanks again. You guys are awesome.
Wednesday, December 17, 2003 12:06:55 PM (Pacific Standard Time, UTC-08:00)
A critical component -- the file must have .format.html in the name. I was trying with test.html and wasn't getting anywhere until I renamed it to test.format.html. Now it works as expected.

Thanks for this pointer. It's exactly what I've been looking for.
Friday, December 19, 2003 4:28:15 AM (Pacific Standard Time, UTC-08:00)
This is exactly what I was looking for. Thanks.
Wednesday, October 12, 2005 3:56:46 AM (Pacific Daylight Time, UTC-07:00)
Same here! Thanks for the info!
Monday, April 07, 2008 3:35:32 PM (Pacific Daylight Time, UTC-07:00)
This is excellent. But how would I make the home page for dasBlog a landing page (rather than my blog page) and then have the actual blog page something like www.xavierpacheco.com/blog. Thanks for the tip!
Sunday, June 08, 2008 5:00:57 PM (Pacific Daylight Time, UTC-07:00)
You've got "This file should just contain the HTML that would normaly between the tag". Can you complete this sentence? I can't get this technique to work after trying everything. Between what tag? Body?, HTML?
Bob
Sunday, July 13, 2008 5:49:49 PM (Pacific Daylight Time, UTC-07:00)
Bob, I belive <body> is what I meant. All the HTML you would normally have in between the body tags.
Thursday, August 14, 2008 3:59:01 PM (Pacific Daylight Time, UTC-07:00)
Great hack, I saw it before but was in a hurry and didn't take the time to read it through. Maybe you just explain it better, either way thanks for the tip/trick.
Comments are closed.