2006-09-01

Blogger beta templates

I got curious about the Blogger Beta templates and had a peek of my own. They still merit the "Beta" tag, but a lot is already in a working or partially working state. Maybe even most of it, though I sense a still partially non-exposed aspect of their widget system, which would be a lot of fun to play with once released. Conceptually, it's a system similar to RXML or CFML; a markup language for server-side composition rendered dynamically with every page-load. Blogger's new markup language seems to be called GML (Google Markup Language, most likely), judging by the namespace markers.

It's probably similar to other blog platform widget markup languages, but I do not have that frame of reference. A few years as a developer of and technical writer on Roxen WebServer yielded me some high profile knowledge on the making of template languages, though, and there are a few perls to pick in Blogger's new template engine.

Some concept docs are already in place about the page elements; <b:section> tags in your template mark places where widgets can be placed in the page flow and <b:widget> tags (placable inside the former) define the part of each widget that gets rendered into the web page (server side) on the spot where the tag was encountered in the template. (Presently the pageType attribute doesn't seem to be handled as documented -- at least any I enter are swallowed, ignored and wiped away the next time I load the template.)

To me, what we see so far is about a quarter of to maybe half of what constitutes this widget engine. Each widget also has a configuration view, storage backend and data object model, all tying into one another, and the rendered page as a whole has a document object model. We don't have docs about or access to either yet, but I'd love to eventually see information about this Blogger DOM. With luck that is what we will see in the detailed widget tags docs, once they show up. With even more luck, we will eventually also see and be able to make and share widgets of our own, complete with configuration views and server-side persisted data. (Here's hoping, anyway.)

This post will enter even more speculative grounds from here, as I'm just theorizing around my findings about the mechanics of this template system now -- there is little trial-and-error empirical evidence backing it, so expect flaws where my intuition was not compatible with those of the Blogger template engineers'. All tags mentioned may (and mostly do) contain additional tags, unless specified otherwise. I'm addressing a programmer audience below, assuming some familiarity with variables, flow control and XML markup.

Data types

The data widgets handle comes in several varieties. First, there are the scalars -- strings, maybe (or at least conceptually) integers (perhaps just string-to-integer coercion rules), enums (pick-a-string-from-a-given-list) and booleans (the enum "true" / "false"). Second, there are the compound types; objects and collections of objects. All data coexist in a server-side object model operated on by the new Blogger tags and custom-namespace expr:* attributes that you may use with regular HTML tags too.

data: tags

Scalars are available for insertion directly into the document by way of the tags in the data:* namespace. Just name the scalar and wrap it in a tag and its value gets injected into the document, i e <data:blog.pageType/> would yield index for the root (or a label lookup) page, archive when on an archive page and item for a post page. The complete layout of the Blogger DOM is not addressed by this post, but keen researchers are encouraged to link back to this post from their references and show up in backlinks here, for the benefit of all readers (including myself :-), until Blogger takes its time to publish one.

expr: attributes

As XML documents don't allow tags inside tag attributes, the expr:* attribute namespace, which you can use with any HTML tag, lets you expand data there too in a similar fashion. If, say, you wanted to expand the data:blog.homepageUrl value into the href attribute of a link tag, you would write that as <a expr:href='data:blog.homepageUrl'> -- just tuck on the attribute name you would have used after the expr: prefix. If what you wanted in the attribute was a combination of a variable and something else, expr:* attributes allow a certain amount of flexibility via string concatenation, such as expr:href='data:post.url + "#comment-" + data:comment.id' (note the different types of quotation used; apostrophes to encase the full XML attribute and quotation marks to hold the string literal).

The rest of the tags

<b:includable>

Moving on and in another level from the <b:widget> tag, we see one or more <b:includable> tags. You might compare these with the <xsl:template> rules of an XSLT template; they may invoke one another, passing along parameters (one parameter, anyway).

id (mandatory)

This is the (widget unique) name, by which the template rule is invoked from elsewhere. Every widget tag has an includable with an id attribute "main", which is what gets run when the widget is rendered into HTML form.

for (optional)

The for attribute names the incoming parameter for the variable scope visible within the includable, overshadowing data under the same name in the caller's scope. Not all includables accept parameters. In the absence of a for parameter (when a variable was passed), the name defaults to data. The type of the parameter passed to the main template is given by the type attribute of the <b:widget> tag, and its exposed object model varies accordingly.

<b:include>

This tag invokes another (or possibly the same, if recursion is supported) includable within the same widget definition.

name (mandatory)

The name parameter corresponds to the id parameter of the <b:includable> you wish to invoke.

data (optional)

The data parameter selects what data you wish to pass along to the <b:includable> you are invoking (as named in the current variable scope), if any.

<b:loop>

This construct is the iteration clause, that lets you loop over a collection, repeatedly applying the contained markup block once for every item in the collection.

values (mandatory)

This attribute names the collection to iterate over. For instance, you could loop over every label using data:labels for a type="Label" widget.

var (mandatory)

In the scope inside of this tag, this names the variable holding the object for the present loop iteration. It is the logical equivalent of the <b:includable> tag's for attribute. In other words, if we supply a var="comment" parameter and the objects in the collection have a body property, we can print that using <data:comment.body/>.

<b:if>

This tag is the conditional, picking one of two different outputs. In the absence of an <b:else/> branch, it either outputs its full contents or nothing at all, depending on the conditional. With an <b:else/> tag present inside, it picks the part before or afterwards depending on the result of the test.

cond (mandatory)

This attribute lists the condition to test on. It may be just a variable name (i e cond='data:post.allowComments', to test a boolean's truth value), or an expression, such as cond='data:blog.pageType == "item"' (again note the use of alternating types of quotation; one for the XML attribute encasing, another for the string literal). These expressions may use the operators ==, for testing for equality and != for testing for non-equality.

<b:else/>

This tag may not have any content, and it may only appear inside an <b:if> tag. It splits the contents of its parent in two, the first being the branch to execute when the conditional was met, and the second when it was not.

14 comments:

  1. Thanks so much for mentioning the concentation thing with regards to expr:*! Been looking for that!

    ReplyDelete
  2. It's way too complex for most people. Prefered the old way.

    ReplyDelete
  3. Yeah, it's so complicated, you can't use blogger templates downloaded over the internet. Unless, I suppose, you're pretty knowledgable with HTML/CSS codes. Hopefully, blogger will be able to fix that. In the meantime, I'm going to stick with the old blogger. :)

    ReplyDelete
  4. Thanks for your sharing!
    The pageType is sweet,
    Hope the guy in Blogger can fix it soon;)

    ReplyDelete
  5. The whole "beta" format is confusing me to no end! My blog looks fine (I think) but I want to make the sidebar to cut off like halfway through, I don't want it going all the way down to the bottom.... http://frustratedauthor.blogspot.com

    See what I mean? It would look so much nicer if it cut off and the background took over! If you have a quick fix for this or if you have any other suggestions please let me know! Thanks for all the great info, I really enjoyed the post!

    ReplyDelete
  6. Do you know why the hell they aren't just using standard XSLT for their templates?

    Their format is just way too complicated and badly documented IMO. There is really no problem with using XSLT on an entry in their atom feed, see http://dunkelstern.no-ip.org/planet/ that site is completely generated from the blogger Atom feed and some XSLT scripts (download them on the bottom of the site if you like (creative commons license), they are packaged in the shell-planet distribution).

    And of course I don't want to learn a new templating language everytime I choose to use another blog service provider ;)

    ReplyDelete
  7. No. Might be the Not Invented Here syndrome, might be that they wanted to achieve some level of lock-in, might be that XSLT is more resource intensive than their own hack, or any number of other aspects. One I find not all unlikely is that XSLT in and of itself doesn't offer what their own cool page templating system does.

    ReplyDelete
  8. Thanks for all the information.. i personally think that ppl are messed up with templates afetr switching to beta. thank god that am still using blogger classic... haap with it..

    ReplyDelete
  9. hi johan,

    before i dont like blogger beta. ive been having issues with it like redesigning and adding custom templates. they just wont work. but now, Ive notice the more you use it and the more you get used to its features, redesigning becomes easy. esp the page elements, adding a page on your blog has never been easier. i made an
    agloco
    blog using blogger beta and i like the final redesign i made :)

    ReplyDelete
  10. I just want to figure out what values I can get. I'm not finding any references on the data I can query from the template. ATM I'm trying to datestamp every blog but the template only puts one per day rather than on every blog.

    ReplyDelete
  11. I know this is a really old topic but somehow I need to implement some template engine which can include blogger templates. is that possible ?

    ReplyDelete
  12. Blogger did, hence it is possible. If you need to ask, you are probably not capable to do it on your own. You may find the bloggerdev mailing list a better place to ask for help.

    ReplyDelete
  13. Wow. Really, it's so helping me! Thank you!

    ReplyDelete

Limited HTML (such as <b>, <i>, <a>) is supported. (All comments are moderated by me amd rel=nofollow gets added to links -- to deter and weed out monetized spam.)

I would prefer not to have to do this as much as you do. Comments straying too far off the post topic often lost due to attention dilution.

Note: Only a member of this blog may post a comment.