Friday, 26 September 2014

How to search for pattern in blogger template xml file - quick way!

Ok, you are using blogger. And you love it! It is free, meaning that web hosting is free and domain name is free. It is pretty simple to change template or to add something. But... first time that you have to change something that is not predefined by google blogger team you will have to start using HTML editor that is embedded in blogger. Changes that you need to make are considering template that you use. If you are not HTML expert then you modification of template file goes something like this: 
step 1: find how to change what you need on Internet
step 2: make necessary changes in HTML code

Instruction on Internet goes like this: "Find this pattern and insert this after that pattern or delete that" But finding that pattern can be tricky because I had trouble using search in HTML editor because it did not work for whole xml file but just for part of file that you are can see in editor window. So finding that pattern goes something like this: search pattern, scroll down, search pattern, scroll down, etc. For instance, .xml template file for template that is used on this blog has 2222 lines and in editor window I can see only 23 lines. 
So how to quickly find pattern that you are looking for? I use this method. Backup your template .xml file. This will download xml file from blogger to your computer. Use any text editor to find in what line your pattern is in. I use Cygwin. Here is example. My pattern is <data:post.body/>. I look like this

$ grep -n '<data:post.body' template-3270296475170057061\(1\).xml
1772:            <data:post.body/>
1899:<div expr:id='&quot;summary&quot; + data:post.id'><data:post.body/></div>
1903:<b:if cond='data:blog.pageType == &quot;item&quot;'><data:post.body/></b:if>
1905:<b:if cond='data:blog.pageType == &quot;static_page&quot;'><data:post.body/></b:if>


So in blogger HTML editor I go to line 1772 and that insert or delete code that I need.



No comments: