Sitecore Log Analyzer

November 28, 2012 Leave a comment

Everyone in the Sitecore developer community has had a site that has been somewhat unstable for seemingly no reason.  At that point they do a few things to diagnose, one of which is most likely to review the log files.  About a year ago I made a little application to help me analyze logs for the sites I worked on, and just recently I’ve added a few features to it and put it out for the world to see at https://github.com/PCaponetti/Sitecore-Log-Analyzer

Check out the demo at http://www.youtube.com/watch?v=b5BZQqQCDcg&feature=youtu.be

Advertisements
Categories: Uncategorized

Sitecore Mobile: How to Make Your Site Mobile-Friendly, Fast on your Phone

January 26, 2012 Leave a comment

I’ve been off blogging for a while, I know.  I’m back on, blogging for Verndale.

Check out the first of many here

Categories: Uncategorized

Make your item names more URL friendly

January 6, 2010 Leave a comment

Happy new year!

Have a quick post to help everyone who’s ever had a full site made only to have a client ask for a URL convention. A common convention to use is to separate words with hyphens instead of spaces.

Now I hope all you guys keep encouraging proper SEO friendly URLs from the beginning so this will not become an issue. I also hope you base any references to specific items on item ID and not path and name so that changing URLs is not an issue.

Now, assuming you are all set to monkey with the item names, hence URLs, here is how you can do it easily and keep a convention enforced: event handlers.

All you have to do is handle the item:created, item:renamed and item:added events. Initially, to change all currently made items you will also handle the item:published event and do a publish site with the “Republish All” option.

All of the event handlers will call the same function with the item that comes in as a parameter.  Inside the function, we will check the item’s name and see if it complies with the URL convention.  If it does, we do nothing, if it does not, we save the old name, modify the name to comply with the URL rules and then set the old name as the display name.  Sample code is provided below

IMPORTANT NOTE: remember, everything in Sitecore is an item!  You do not want to rename system templates, workflows, or other functionality items that ship with Sitecore!  You must add logic into your URL cleaner to only clean the names of items under your Home item in the content tree.

    /// If the item needs to be renamed, start an edit, rename it and commit
    /// the edit
    public void cleanName(Item item)
    {
        if (item.Name.Contains(" ") || item.Name.Contains("&"))
        {
            if (validItem(item))
            {
                try
                {
                    item.Editing.BeginEdit();
                    item.Appearance.DisplayName = item.Name;
                    item.Name = item.Name.Replace(" & ", "-and-").Replace("&",
                      "-and-").Replace(" ", "-").Replace("--",
                      "-").Replace("--", "-");
                    item.Editing.EndEdit();
                }
                catch (Exception ex) { }
                finally { item.Editing.CancelEdit(); }
            }
        }
    }

    /// VERY IMPORTANT!!!!!  REMEMBER: everything in Sitecore is an item, so
    /// only change the names of the items under your Home in the content tree!!!
    public bool validItem(Item item)
    {
        if (item.TemplateName.Equals(
          "INSERT NAME OF YOUR HOMEPAGE TEMPLATE HERE!!!",
          StringComparison.CurrentCultureIgnoreCase))
        {
            return true;
        }
        else if (item.Parent != null)
        {
            return validItem(item.Parent);
        }
        else
        {
            return false;
        }
    }

To get more information on handling events check the SDN page on handling events

Categories: 1

Custom Item Editors in Sitecore

December 27, 2009 5 comments

I know, I know; this post was supposed to be a post about the solution to recurring events but alas, the holidays and other priorities led me to push off that solution until January.  I also know that Sitecore is going the way of the page editor as of late, but say you have a complex third party database holding information that you don’t want to sync into your Sitecore install as items to be manipulated in the page editor.  These items may be too complex and require a small .Net app to manipulate.  In this case, a custom Sitecore editor is your answer.

I realize that making custom item editors is old hat for many developers, but was shocked on how hard it was to find a full walktrough on how to create and install one.  If you come across a spot in a solution where a custom editor is necessary, do the following three steps

  • create an aspx page with the desired functionality
  • create an application item in the core database for it under /sitecore/content/Applications/Content Editor/Editors
  • set the editor in the standard values of the template you would like to manipulate

Here’s a slightly more in-depth version:

Creating the .aspx page

When creating the .aspx page, remember that just like in a layout page your Sitecore.Context is completely intact, accept for the current item.  To get the current item, use the Sitecore ID that comes in as a query string parameter “id”.  The code looks something like

Sitecore.Context.Database.GetItem(Request.QueryString["id"]);

Version (“vs”) and language (“la”) are also in the query string for more in-depth multi-language sites with workflow.

Once you have the item(s) you want to work with you can feel free to use whatever .Net controls you would like to display, edit, delete, whatever them.  Keep in mind this page is going to show inside of Sitecore, so CSS appropriately.  Hint (selected from the Sitecore stylesheet and slightly modified):

BODY
{
  margin: 0px;
  padding: 0px;
}
H1
{
  font-size: 14pt;
  color: #072D6B;
  font-family: Franklin Gothic Medium;
  margin: 5px;
  padding: 0px;
}
H2
{
  display: block;
  background-color: #D9D9D9;
  border-bottom: 1px solid #CCCCCC;
  border-top: 1px solid white;
  color: #555555;
  font-family: tahoma;
  font-size: 8pt;
  padding: 1px 5px;
  margin: 0px;
}

Creating the editor item

To create the application item in Sitecore to back this .aspx page we just created, login to the Sitecore desktop and select the core database.  Inside the core database’s Content Editor, go to /sitecore/content/Applications/Content Editor/Editors

image of content tree for core db

Inside the Editors folder, create a folder to hold your cutsom editors.  I called mine “DHS Custom” in the above image.  In your custom editors folder, insert an item of template /sitecore/templates/Sitecore Client/Content Editor/Editor.

In this item the only required field is the Url, which will point to the .aspx page you have created in the previous step.  You might also want to change the icon, and check the “Refresh on Show” checkbox that will force a refresh of the .aspx page every time it is shown.

Setting the Standard Values

Now we are ready to install the editor on the item we would like to edit.  Navigate to the Standard Values of the template of the item you would like to install the editor on and find the “Editors” field.  If you cannot find the “Editors” field, make sure you have “Standard Fields” checked under the “View” ribbon menu.  Click the “Edit” button above the field and select your newly installed editor.

That’s it.  You’re done!  Notice that the editor will show up as a tab in the Standard Values and every item of that template type now.

NOTE: the save button will obviously not work in the new tab with your custom item editor unless you capture the save button press event.  Capturing the Save button press is an ambitious task and not documented by Sitecore, but I’ve recently found a blog post that describes this (thanks to Mark van Aalst!) http://www.markvanaalst.net/2009/08/19/creating-a-item-editor/

Feedback

Please hit me with some feedback.  I need to know if this is the type of stuff you want to hear.  Too much detail or too little?  Too easy a task?  Please take a second and click the poll below.

Thanks for reading

Categories: Sitecore

Hello World!

December 21, 2009 Leave a comment

Hello world.  My name is Paul Caponetti.

I’m the CMS Lead and Sitecore Expert at a small Boston-based interactive agency.  I’ve been working with Sitecore for about 2 years and love the platform.  I’ve used Sitecore to build everything from a ten page company site, to a multi thousand page, highly functional, high traffic site.

Through working with Sitecore I’ve come up on many issues that have been solved by the Sitecore community.  Whether it be through Sitecore meetups, SDN or Blogs, the answer is usually out there.  I feel very much obliged to give back, and to add to this vast knowledge base.

I will try to commit to this blog weekly.  I’ll touch on everything from low-down configuration options to high level best practices.

This coming week I will be working on a quick and simple solution to an old pain point for Sitecore: recurring events.  An event template and content tree is common occurance in websites, but making that event re-occur week after week, or day after day, is nearly impossible.

Stay tuned!

Categories: Sitecore