Fix Broken Category Class Title in SharePoint 2010 Blog site

December 12 2012 6 comments

There is an old bug in SharePoint 2010 that surfaces to me from time to time: blog site category title doesn’t render correctly if it contains some funny foreign characters we Finnish like to use in our language.

The power of umlauts is too much for this blog

The reason I’m writing this down right now is that I’ve got a case tomorrow at work where I have to fix this. This happens on a regular basis and I always write the fix from the scratch. Only this time, I don’t have to do it. I’ve got the CTRL-C / CTRL-V solution right here.

Buğra Postacı has blogged a solution that involves SharePoint Designer and manual labour earlier this year. As I’m not a fan of either I decided to use some nasty client script to hack the problem.

But let’s start with CSS!

Those question marks look weird in the category title, let’s get rid of the title by applying a CSS display: none.  As we’re going to use JavaScript for our fix, it will take a few milliseconds to complete. I’m doing this CSS hiding to prevent flicker until the JS kicks in. Pure optional, that is.

h3.ms-CategoryTitleMonth { display: none;}

Let's hide the title with a bad word, there might be children watching

The Javascript

I’m going to be using my favourite DOM manipulation library, jQuery combined with some vanilla JS but you can use whatever works for you. I’m just using the jQuery to find the element, so it is a bit of an overkill here but this is just an example.

First we need a helper function getUrlVars() to parse the URL and get to the hash. We will be using that to get the category name.

function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

When the page is ready, we set the textual content of the category title to the decoded hash value and show the element (it was initially hidden with CSS). I’m using PageLoad() here because the page I’m using has a postback but once again you can use whatever works for you.

function pageLoad() {
    $j('h3.ms-CategoryTitleMonth').text(unescape(getUrlVars()['Name'])).show();
}

Which translates to:

The Iceman cometh!

That’s all there really is to it. Have fun.

Popularity: 2% [?]

6 comments to “Fix Broken Category Class Title in SharePoint 2010 Blog site”

  1. Jukka Kotamäki says:

    Great Article, Tuukka!

    Another option would be to create a small feature, which will copy to Layouts\XML\Blog.xsl – file to a new name and copy a new blog.xsl file to that folder. This blog.xsl file has only one difference: there’s a place where the “safe characters” are defined: just add to the list ÄÖÅ and äöå characters :-) and by magic the blog starts to work.

    More precise: search for and a place:
    !’()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ_abcdefghijklmnopqrstuvwxyzåäö~

    -Jukka-

  2. Jukka Kotamäki says:

    oops, the previous comment seemed to lost the thing what to search for: template name=”url-encode”.

    Hope nothing is missing now when I hit Submit :-)

    -Jukka-

  3. Carl says:

    Hi there colleagues, how is everything, and what you want to say regarding
    this paragraph, in my view its in fact awesome in favor of me.

  4. We produce Bitcoin miners and Bitecoin miners. We are the direct vendor.

  5. Hello, I wish for to subscribe for this web site to get newest updates,
    therefore where can i do it please help.

  6. magnificent issues altogether, you simply received a new reader.
    What would you suggest in regards to your publish
    that you just made a few days ago? Any sure?

Leave a Reply