Understanding the blogger template - 1

Jan 24, 2009

The blogger template is a xhtml document which is rendered based on variables. These tutorials aims at helping to understand the blogger template and hence to experiment, learn and change it. Blogger template has mainly three types of variables one which controls the flow of the code, one which pulls data from the databases behind and the third are expressions. This variables are then distinguished with the help of following xml namespaces. This one is the first in series of three tutorials.

This tutorial will mainly concenterate on the template basics and the b:namespace. The index for all tuts:


  1. Blogger Template Explanation - Sections, widgets, includables, includes. b: namespace

  2. Blogger Template Explanation - Data access. data: namespace elements.

  3. Blogger Template Explanation - How to use expr: namespace - customize links.




Before you start experimenting with your blogger template I will suggest you do two things. Create a sandbox blog which you should delete once you are done experimenting, so that the url is free for some other poor blogger. Now Download the current template of your blog i.e., you should backup both your widgets and the template file itself. You can search for how to do this on google or wait until I write one tutorial on that :).

To understand/experiment with your blogger template I will suggest don't do it on your blogger "Edit HTML" page. Use the template that you downloaded with some advanced text editor. I would recomment Notepad++ but you can use whatever you like to understand your blogger template.

The blogger template is a xhtml document based on http://www.w3.org/1999/xhtml specification. The following namespaces are used in the blogger template:


<html
xmlns = 'http://www.w3.org/1999/xhtml'
xmlns:b = 'http://www.google.com/2005/gml/b'
xmlns:data = 'http://www.google.com/2005/gml/data'
xmlns:expr = 'http://www.google.com/2005/gml/expr'
>


These namespaces will be used throughout the xml document to fetch and display data. So this tutorial is going to explain mainly the variables in the 'b' namespace. The variables in this namespace mainly control the layout and control flow of the template. This helps in placing the elements on your blog at certain location and if-else conditions as well as loops. More about the namespaces later.

The template is mainly divided in sections. This sections will include widgets. Widgets will have includables. includables are useless unless you use it by using the include tag.

The Section Tag.


Section tag determines the division of your blogger layout. The section cannot contain any code directly. Only widgets are to be inserted inside it. Following is the format and attributes are supported by the section tag.


<b:section [attribs] >
</b:section>



  1. id (Required) A name identifying the section must be unique. This id can be used to identify the section after the blogger rendering is done. These section tags will show up as div tags having the same id.

  2. class (Optional) Common class names are 'navbar,' 'header,' 'main,' 'sidebar,' and 'footer.' If you switch templates later, these names help Blogger determine how best to transfer over your content. However, you can use different names, if you like. You can use them to stylize your content.

  3. maxwidgets (Optional) The maximum number of widgets to allow in this section. If you don't specify a limit, there won't be one.

  4. showaddelement(Optional) Can be 'yes' or 'no,' with 'yes' as the default. This determines whether the Page Elements tab will show the 'Add a Page Element' link in this section.

  5. growth (Optional) Can be 'horizontal' or 'vertical,' with 'vertical' as the default. This determines whether widgets within this section are arranged side-by-side or stacked.



The Widget Tag.


Widget Tags are included inside section tags. There are two ways of viewing the html code on the "Edit HTML" page. One is simple form which gets displayed by default. The other is by using the "Expand Widgets" checkbox. In the simple form the widgets are included inside the sections with the single tag format i.e., opening and closing tag in one.

<!--Simple form.-->
<b:widget [attribs] />

<!-- Expanded form. -->
<b:widget [attribs] >
</b:widget>


A widget may have the following attributes:

  1. id (Required) May contain letters and numbers only, and each widget ID in your template should be unique. A widget's ID cannot be changed without deleting the widget and creating a new one. Similar to the section tag's id, widget tags also get converted to div tags having the id same as used here.

  2. type: (Required) Indicates what kind of a widget it is, and should be one of the valid widget types listed below.

  3. locked: (Optional) Can be 'yes' or 'no,' with 'no' as the default. A locked widget cannot be moved or deleted from the Page Elements tab.

  4. title: (Optional) A display title for the widget. If none is specified, a default title such as 'List1' will be used.

  5. pageType: (Optional) Can be 'all,' 'archive,' 'main,' or 'item,' with 'all' as the default. The widget will display only on the designated pages of your blog. (All widgets display on the Page Elements tab, regardless of thier pageType.)


The widget types that can be specified are: BlogArchive, Blog, Feed, Header, HTML, SingleImage, LinkList, List, Logo, BlogProfile, Navbar, VideoBar, NewsBar.

The widget in simple form will just show you the placement of the widget. But if you need to edit the widget itself, then switch to the advanced form i.e., Expanded widgets.

The includables Tag.


A widget is a collection of includables and typically a main includable. Includables as their name suggests are piece of code that can be put together to avoid repetetion. This includable then can be included in one more places. Apart from removing repetition the includables also help in understanding the structure of the widget. Includable tag is also part of b namespace. So it will have the tag in this manner.


<b:includable id='[some-unique-id]' [attribs] >
</b:includable>


The includable tag has the following attributes:

  1. id: (Required) A unique identifier made up of letters and numbers. Note: a widget must contain atleast a single includable and the id for that must be main.

  2. var: (Optional) An identifier made up of letters and numbers, for referencing data within this section. The data will be referenced similar to the namespace i.e., if var='a' is used then the title in data can be referred as a:title.



The include Tag.


The includable created above needs to be included in the widget for that we use the include tag. If your widget is having only a single includable then in that case the id of that includable should be main and for that a separate include is not required. That single includable will be included by default. The include tag contains two attribs mainly name refers to the id of the includable and data refers to var of includable. The includable tag is self closed and another closing tag is not required. The format is as shown.


<b:include name='[the-includable-name]' data='[the-expression-for-var]'/>


The attributes name and data:

  1. name: (Required) This name will be pointing to the includable which is to be included. There should be a includable with the id as this name.

  2. data: (Optional) Like a parameter is passed to function this data is passed to includable. It is a peice of data to pass on to the includable section. This will become the value of the var attribute in the includable.



We can have any name for includable but it must be unique for that widget. This includable can then be included in one or more places in the widget using the include tag.
Next lets discuss two more tags from the "b" namespace. They are if / else and the loop.

The if / else Tag.


The if/else tag is displayed as shown.


<!-- Only if-->
<b:if cond='[some condn check]'>
[Then do this]
</b:if>


<!-- both if and else-->
<b:if cond='[some cond check]'>
<!-- [Then do this] -->
<b:else/>
<!-- [else do this] -->
</b:if>


From the code above the working of if and else would be quite clear. One thing to note is that the else tag is a self closing one. To understand the condition see the following examples.


<!-- to check a boolean variable. -->
<b:if cond='data:useImage'>
<!-- [execute if the header for your blog is image instead of text] -->
</b:if>

<!-- to compare equivalence of two values-->
<b:if cond='data:blog.pageType == "item"'>
<!-- [True if the current page is an item page (post page).] -->
</b:if>

<!-- to compare non-equivalence -->
<b:if cond='data:displayname != "Fred"'>
<!-- [True if this is not Fred's display name.] -->
</b:if>

<!-- comparing greater than, less than-->
<b:if cond='data:post.numComments > 1'>
<!-- [True if the current post has more than one comment.] -->
</b:if>


They say for any language if you know to control the flow you are done with the basics. So for completing the basics of blogger template we need to learn about if-else and a looping feature. One done One to Go. So lets discuss the loop feature now.

The Loop Tag.


This is also part of "b" namespace. It behaves as any loop should i.e., for every element in some set of elements you can do something. For e.g., In a set of comments display each comment. If you are looking for customizing your comments display you may have to look into this loop. The usage will be more clear once you have a look at the syntax.


<b:loop var='some-identifying-var' values='set-of-something'>
<!-- [For every var in the values i.e., for every data in the set of data do something here] -->
</b:loop>


Now we are done with the basics, but one important thing remains - Displaying your data. Obviously you just dont want to have a beautiful page without any data. You need to display some data. For that we will have to learn about the data namespace.

Therefore data namespace contains the most important variables and if I mention it all in here it would be too cluttered. I will write a separate article on that. And as you must know you learn more experimenting then reading. So get your coffees ready and start experimenting with the code.

You are more than welcome to add more help in the comments. Also if you want or have a better explanation add it up in comments. If you have any doubts put them here. I would answer them if I know :).
Prevent Mobile Loss

Jan 10, 2009

Found my love my mobile


As I have mentioned earlier in the post "She broke up with me" my love, my mobile was lost in an auto rickshaw while commuting to office. Thanks to the prayers I & you made I am back again with her :). We did meet again. The breakup didn't last long. Hope it doesn't ever happen again.

The burning question that everybody is asking me now:

How to get lost / stolen mobile back?

When you search the net for lost mobile you will find thousands of links and pages, but very few posts from people who recovered it.

One of the reason I got mobile back is because I was very well prepared that this crisis might occur. Other reasons are chance and luck, which are beyond our control but the following things should be taken care of.

First: When you buy a mobile, keep your bills safe. Don't throw them away. Make sure your Bills are duly stamped and should contain your name, manufacturer name, model name and Product / Serial Number of your mobile. Keep all the manuals warranty etc that come along they are helpful although not for recovery.

Second: Take a note of your IMEI ( International Mobile Equipment Identity ) number. Its usually found printed on the phone under the battery along with the serial number. It is a unique number assigned to each mobile equipment. This number is unique to the device and has no relation to the SIM (Subscriber Identity Module) which stores the IMSI (International Mobile Subscriber Identity) and hence to sevice provider. It was introduced mainly to control mobile thefts. The logic used for tracking is as follows. Whenever a mobile connects to a GSM networks (IMEI is only for GSM networks) along with the SIM number and other information the mobile also transfers the IMEI number to identify itself as a valid device.
Now when a mobile is stolen or is to be tracked as who is using it, a alert can be placed on the IMEI number. The next time the number comes on the network it is identified as a invalid device and the alert is triggered on it with all the details i.e., the phone number / sim number etc, from where the person's address who is using the SIM etc can be found. A point to note here is that although most of the countries follow this standard and have laws implementing IMEI number for mobile devices, some countries although, like Singapore etc don't have such laws and there are devices without IMEI number. There are even techniques to remove/tamper the IMEI number of mobile equipments. But this techniques are against the law in many countries and require high skill and understanding. Its basically like a hack and proficient people can do it. More on IMEI number here.

Third: Although this wont help you find your mobile but will help you mitigate the loss, get an insurance on it. In many countries getting an insurance is a general practice while buying mobile. If your device is costly why not take it.

Fourth: Try and get a backup of all your data i.e., keep synchronising your device with your laptop or whatever. The activesync on windows mobile takes care of backing up your contacts, calendar appointments, E-mail, Tasks, Notes, Favourites, some files and other media. You can use some other Sync softwares which can keep your storage / memory card in sync. Make an habit of connecting your device to laptop (bluetooth sync is hasselfree).

Fifth: There are software which can be installed on the devices supporting multimedia i.e., having PC connectivity installed with OS as Windows Mobile, Symbian, Palm OS etc. There are only a few of these software which I am going to tell you about. These software are again a kind of hack and tampering done to track SIM card change. The logic of this software is simple. There is predefined configurable mobile number stored on your device (like in the mobile registry) which will be notified by a SMS, being sent in the background with the information like the new SIM number and mobile number inserted. Some more sophisticated softwares also insert the GPS coordinates of the mobile when sending the SMS, provided your device had GPS installed on it. So you can find out the person yourself who did this to you. You may find some free software look for them. This point may not be applicable to many of you and I admit its a bit geeky.

Sixth: Take Care Period.

Well I took care of most of the above points but I could not install these software on my device because of the performance tweak I did a few days before losing it. When I was talking about the performance tweak in the last post I was talking about this. The tweak basically was that I had formated my Windows mobile 6.0 and installed windows mobile 6.1 and along with that changed my IPL and SPL ( more of it on someother day if interested get started here). It freed a lot of locked memory on my device. So basically after doing it I did not install these software and the next day the mobile was lost.

Its basically like a stitch in time saves nine. So any precaution that you can take is good. With this all done you might not even lose your mobile. And if you lose it chances are that you will be back with your love as I am.

continued in...

So now how to Recover Lost mobile?



.
Traveler IQ Quiz Game

Nov 30, 2008

So how nicely do you know the world you live in?

OK... Did you ever wish that you live your job or whatever you do and go for a trip around the world. Get into the exquisite hotels around the world. From East to West, From North to South.

Well Fella ! before that lets check how much you about the world. Turn on your imagination and bring the world map in front of you. Then try and imagine these places.

1. Grand Canyon - USA
2. Great Barrier Reaf - Australia
3. Florida - USA
4. The South Island - New Zealand
5. Cape Town - South Africa
6. Golden Temple - India
7. Las Vegas - USA
8. Sydney - Australia
9. New York - USA
10. Taj Mahal - India
11. Canadian Rockies - Canada
12. Uluru - Australia
13. Chichen Itza -Mexico
14. Macchu Pichu - Peru
15. Niagara Falls - Canada/USA
16. Petra - Jordan
17. The Pyramids - Egypt
18. Venice - Italy
19. Maldives - Maldives
20. Great Wall - China
21. Victoria Falls - Zambia/Zimbabwe
22. Hongkong - Hongkong
23. Yosemite National Park - USA
24. Hawaii - USA
25. Auckland - New Zealand
26. Iguassu Falls - Argentina/Brazil
27. Paris - France
28. Alaska - USA
29. Angkor Wat - Cambodia
30. Himalayas - India/Nepal/Tibet
31. Rio de Janerio - Brazil
32. Masai Mara - Kenya
33. Galapagos Island - Ecuador
34. Luxor - Egypt
35. Rome - Italy
36. San Fransisco - USA
37. Barcelona - Spain
38. Dubai - Arab Emirates
39. Singapore - Singapore
40. La Digue - Seychelles

So how many could you picture, How many could you locate? Well, for most of you when you were thinking of a world trip you were imagining of those luxury hotels, historic places, exotic beaches, and what not.

Meaning you must have forgotten the aim of this blog. To test and challenge your IQ. Let me help your imagination and take you to a wonderful Game/Quiz by TravelPod. This will brush up your GK and IQ and get you ready for that trip.

So here is the link for The Traveler IQ Challenge™. This game is also embedded below.

If you face any display problem please play at the link given above.


This Traveler IQ challenge compares your geographical knowledge against the World's Original Travel diary's other 3,372,655 travelers who have taken this challenge as of Sunday, November 30, 2008 at 03:44PM GMT. (TravelPod is a TripAdvisor Media Network member)


Checkout wikipedia for the places you know, you know but can't remember :). So when you have completed the challenge and got your Map IQ high, You can start packing your travel bags. Until then Happy Quizzing.
Display HTML / JavaScript code in Blogger - How to

Nov 29, 2008

In my last post about How to add Digg to Blogger I was struggling with how to display html code on my page. Showing code in those beautiful boxes without disturbing the layout / indenting was easy but tricky. You need to know css / html and that the Blogger does not support unescaped code. Also to maintain consistency among all this boxes, is another issue. So here is what I did.

Lets have a look first at the box I am talking about.


So the question remains, how to get it?

Easy... just follow this steps.

As blogger wont take html code as it is... meaning you will need to convert it into escaped code. For that get the code you need to any text editor. Then replace all the < signs with &lt; and all > signs with &gt;. Now copy this escapped code to your blog. There is another easy way to do it. Go to this site -> Text -> HTML Entities Encoder. There are two boxes, copy your code into first box. The escaped code will be generated in the next one. Easy isn't it.

Now how to add those boxes. There are a lot of ways to do it. I will show you the one that I used. First we will make a css class in our blogger template. Use this for Basics of Blogger template. In the css section add this code.


.postCode{
background:lightyellow none repeat scroll 0 0;
border:1px inset orange;
height:150px;
margin:10px;
overflow:auto;
padding:6px;
text-align:left;
}

You can change the background/border colors height etc to match your needs. Now, we will use this class with a <PRE> tag to format our code in those boxes. So enclose your escapped code in this manner.

<pre class="postCode">
YOUR CODE
</pre>


Tadaa! You are done.