Dynamic Template plug-in for Windows Live Writer

Download Now
(Right-click and save to your WLW plugins directory)

A note about security: Like WLW plug-ins, templates are powerful and a malicious template could easily damage your system! Don’t use templates from anyone you don’t trust!


Dynamic Template is a plug-in that makes it easier to insert common snippets of HTML or text into your Windows Live Writer posts.

Templates can be as simple as literally the same exact text every time (for example, “Powered by Windows Live Writer”). Or they can get slightly fancier by prompting for input whenever the template is inserted.

Example 1: Hello World

image

If you enter “happy” and hit OK, the string “Hello world, I am happy today.” is inserted wherever the cursor is.

Here’s what the template for the above looks like:

image

The grid above describes the values that the user will be prompted for whenever the template is inserted. Variable Name is the name that can be used to identify the variable from within the template body. Data Type lets you choose what kind of values the user can enter, and also controls what the type of the variable will be. The Label is the label that the user will see.

The Template Body is just HTML, with some additional features. As you can see here, you can use <%= expression %> to include the value of a variable.

Non-programmers can probably stop here. Just using what’s described above, you already have a fair amount of possibilities in terms of templates you can cook up.

Example 2: Technorati Tags

Dynamic Template is more powerful and flexible than many template (or “HTML macro”) systems, because its templates can be written in C#. If you saw the example above and thought “Hmmm, that looks like JSP/ASP,” you’re right. The templating language used here is much like JSP/ASP: it consists of C# expressions and statements embedded into HTML.

For our next example, let’s consider Technorati tags. Windows Live Writer has a built-in “Insert Tags” feature, but lots of folks like to insert their Technorati tags in a style where multiple words are joined by plus instead of space, for example:

Technorati Tags:

This isn’t possible with the built-in tagging feature, which produces:

Technorati Tags:

You can customize the format for the built-in tagging feature, but not in a way that will get you the words separated with plus. (It just occurred to me that you could just type the multi-word tag with + instead of space. But let’s say you didn’t want to do that.)

Here’s what the template would look like:

image

Notice that statement blocks are surrounded by <% and %>.

The input is split linewise to come up with a list of tags. Each tag is URL-encoded for the tagging URL, and has space replaced with plus for display purposes. As you can see, you can use arbitrary C# code (although you are currently limited to using classes in the mscorlib, System, and System.Web assemblies).

Built-ins

In the Technorati example above, a function called UrlEncode is used–that’s one of several built-in functions available to templates. The complete list follows:

  • HtmlEncode(string)
  • HtmlAttributeEncode(string)
  • HtmlDecode(string)
  • UrlEncode(string)
  • UrlPathEncode(string)
  • UrlDecode(string)

These pass straight through to the corresponding methods on HttpUtility.

There’s also one built-in string variable, _content. If the user has anything selected when the template is inserted, the HTML of the selection will be assigned to this variable (requires Windows Live Writer Beta 2 or later).


6 Responses to “Dynamic Template plug-in for Windows Live Writer”

  1. 1 Cody

    Joe,

    How would I use this plug-in to insert a ‘jump break’ into my blog posts using WLW?
    I’ve got the plug-in installed, but am not sure exactly ‘how’ to enable into my posts.

    Your help would be greatly appreciated!

    Thanks,

    Cody

  2. 3 Ragav

    Ok so I have Windows Live Writer and also installed Dynamic template.

    Just like Cody, I want to be able to put jump breaks in my blogposts. I’m using blogger. Here’s my URL if you wish to see it – http://stopmanufacturingus.blogspot.com

    I’m told that I should add using HTML mode. But I don’t know how to use Dynamic template to do this. i don’t even know how to OPEN dynamic template! Can you offer step-by-step instructions on how to add jump breaks using Dynamic template?

    Thanks!

  3. 4 Ragav

    Wait a minute…I have the latest WLW and it has the following actions under the insert tab:-

    Horizontal line
    Clear break
    Split post

    I just figured out that split post does the job of inserting a jump break! Woot!

  4. Ragav: You got it🙂

  5. My brother recommended I would possibly like this blog.
    He was once totally right. This post actually
    made my day. You can not believe just how much time I had spent for this info!
    Thanks!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: