Monday, January 11, 2010

Sitecore Tweets n Tricks


Untitled DocumenHey Folks,

Got some really cool stuff and out of the box solution for things that could otherwise turn into some real headache...


1. Modifying page editor buttons

What would you do if you wanted to add a button to the page editor default toolbar? Well here's what I found.

Locate the page edit button:

Core: /sitecore/system/setttings/html editor profiles/rich text default_old/webeditButtons/

Duplicate an item there and you have a new button. In the datasection on the new item you find 3 options:

Icon - self explanatory

Tooltip - selfexplatory

Click: A call to a javascript function,

(Example)

Striketrough: javascript:Sitecore.WebEdit.execute("strikeThrough", true, true);

Italic: javascript:Sitecore.WebEdit.execute("Italic", true, true);

All the standard javascript execute commands should work

The result is a strikethough button:

Settings:

Click field: "javascript:Sitecore.WebEdit.execute("strikeThrough", true, true);"

Icon field: found an strike through icon in the standard sitecore image library.

Tooltip field: "Strike through"

The javascript-file with functions are found here : website/shell/applications/webEdit.js

Regarding calling sitecore functionality. There is only created 2 functions in the js file:

Insert image:

javascript:Sitecore.WebEdit.insertImage($JavascriptParameters)

Insert Link:

javascript:Sitecore.WebEdit.insertLink($JavascriptParameters)


So if you wan't to make something more that that we would have to write new functions for that.


2. using Sitecore.Kernel.Webutils

Webutils functions are great helper functions as well. If we want to get the url of the server, we can have it as a great help.

Install it in web.config:

<xslExtensions>

...

<extension mode="on" type="Sitecore.Web.WebUtil, Sitecore.Kernel" namespace="http://www.sitecore.net/webutil" singleInstance="true" />

</xslExtensions>


Now declare it in your xslt:

xmlns:webutil="http://www.sitecore.net/webutil"

Now it’s ready for use (example):

<xsl:text>Display Url: </xsl:text><xsl:value-of select="webutil:GetServerUrl()" /><xsl:value-of select="sc:path(.)" />



3. util:GetString

It might not strike us at the first thought but it’s really a common one - util:GetString(string, default).

A xsl:choose used to display the title of an item can be replaced as follows:

<xsl:choose>

<xsl:when test="sc:fld('menutitle',.)">

<xsl:value-of select="sc:fld('menutitle',.)">

</xsl:when>

<xsl:when test="sc:fld('title',.)">

<xsl:value-of select="sc:fld('title',.)">

</xsl:when>

<xsl:otherwise>

<xsl:value-of select="./@name">

</xsl:otherwise>

</xsl:choose>


simpler call:

<xsl:value-of select="util:GetString(util:GetString(sc:fld('title',.), sc:fld('menutitle',.)),@name)"/>



Hope they work for you.... :-)





2 comments:

  1. Nice, sweet and short.

    If this Blog is about hints and tricks, you could probably make each of these into an individual post. Then Sitecore developers could subscribe to the "daily hint".

    This is great. Welcome to the blogosphere. Add a few more posts, and I'll include you in the official Sitecore blog list.

    ReplyDelete
  2. Thanks a lot.
    I would really work on your advice and expect more help in near future coming my way. For i would love joining the elite Sitecore Blog Club.

    ReplyDelete