23 December 2010

Sitecore Terminology maps to Umbraco

Here at ProWorks we have built a web site using the Sitecore CMS (Wasatch Funds) and had a great experience. We are Sitecore Partners and like to use Sitecore when it makes sense. Sometimes the web sites we are asked to build have budget constraints or are just to small to warrant using Sitecore. In that case we typically have been using Sitefinity to build smaller, simpler sites (Forest Seedling Network).
We like Sitefinity, but an open source project called Umbraco recently caught our eye. The similarity to many of the Sitecore like functions is great because we like the Sitecore experience generally. Of course, the functionality may be similar but the terminology is not. Therefore, I’m creating a terminology map to help me keep some of this straight.
This will be a work in progress and here is what I have so far:
Sitecore Umbraco
Templates Document Types
Visual Rendering editor Templates
Layout Master Template
SubLayout Sub Templates
Edit Rich Text Editor settings Stylesheets (can add generated styles to Rich Text Editor)
Renderings (XSLT/Web Controls) Macros (XSLT/Web Controls)
Similar to using items as picklists (somewhat) Data Type to create new field editors
So far there doesn’t appear to be an equivalent to Sitecore SubLayouts in Umbraco (to be able to have placeholders inside of controls/macros).
EDIT: Sub-templates seem to perform the general functionality of Sitecore Sublayouts.
Anything I’m missing or confused on?
Author :- by Jason.
Source:- http://www.proworks.com/blog/2009/07/15/sitecore-vs-umbraco-terminology/

15 December 2010

Sitecore Media URL

For one of my the latest projects the content editors were always trying to get the actual URL to a Sitecore media library item, but there is no easy way to see this in Sitecore. As developers we know it is in the form of /~/media/[ShortID].ashx or /~/media/[Path].ashx, but editors don't want to think about that. They just want it figured out and displayed in front of them.
What I wanted was something similar to the "Quick Info" section that gives develoeprs/admins a quick view into the important properties of a Sitecore item. This is what I came up with.

This minor change to the editor will allow a user to click on the URL of their choice and copy it to the clipboard.
To add this to your site you need a single class and a change to a pipeline.



   1:  /// <summary>
   2:   
   3:  /// The ShowMediaPath class.
   4:   
   5:  /// </summary>
   6:   
   7:  public class ShowMediaInfo
   8:   
   9:  {
  10:   
  11:      private static readonly string SECTION_NAME = "MediaInfo";
  12:   
  13:   
  14:   
  15:      /// <summary>
  16:   
  17:      /// Gets a value indicating whether this section is collapsed.
  18:   
  19:      /// </summary>
  20:   
  21:      /// <value>
  22:   
  23:      ///  <c>true</c> if this section is collapsed; otherwise, <c>false</c>.
  24:   
  25:      /// </value>
  26:   
  27:      private static bool IsSectionCollapsed
  28:   
  29:      {
  30:   
  31:          get
  32:   
  33:          {
  34:   
  35:              UrlString collapsedSections = new UrlString(Registry.GetString("/Current_User/Content Editor/Sections/Collapsed"));
  36:   
  37:              string value = collapsedSections[SECTION_NAME];
  38:   
  39:              return (string.IsNullOrEmpty(value) || (value == "1"));
  40:   
  41:          }
  42:   
  43:      }
  44:   
  45:   
  46:   
  47:      /// <summary>
  48:   
  49:      /// Processes the specified args.
  50:   
  51:      /// </summary>
  52:   
  53:      /// <param name="args">The args.</param>
  54:   
  55:      public void Process(RenderContentEditorArgs args)
  56:   
  57:      {
  58:   
  59:          Item current = args.Item;
  60:   
  61:          if (current != null && current.Template.FullName.StartsWith("System/Media"))
  62:   
  63:          {
  64:   
  65:              MediaItem mediaItem = current;
  66:   
  67:   
  68:   
  69:              if (mediaItem != null)
  70:   
  71:              {
  72:   
  73:                  bool renderMediaInfo = !IsSectionCollapsed || UserOptions.ContentEditor.RenderCollapsedSections;
  74:   
  75:   
  76:   
  77:                  args.EditorFormatter.RenderSectionBegin(args.Parent,
  78:   
  79:                      "MediaInfo",
  80:   
  81:                      SECTION_NAME,
  82:   
  83:                      "Quick Info (Media)",
  84:   
  85:                      "People/32x32/atom.png",
  86:   
  87:                      IsSectionCollapsed,
  88:   
  89:                      UserOptions.ContentEditor.RenderCollapsedSections);
  90:   
  91:   
  92:   
  93:                  if (renderMediaInfo)
  94:   
  95:                  {
  96:   
  97:                      RenderMediaInfo(args, mediaItem);
  98:   
  99:                  }
 100:   
 101:   
 102:   
 103:                  args.EditorFormatter.RenderSectionEnd(args.Parent, renderMediaInfo, true);
 104:   
 105:              }
 106:   
 107:          }
 108:   
 109:      }
 110:   
 111:   
 112:   
 113:      /// <summary>
 114:   
 115:      /// Renders the media info.
 116:   
 117:      /// </summary>
 118:   
 119:      /// <param name="args">The args.</param>
 120:   
 121:      /// <param name="mediaItem">The media item.</param>
 122:   
 123:      private static void RenderMediaInfo(RenderContentEditorArgs args, MediaItem mediaItem)
 124:   
 125:      {
 126:   
 127:          StringBuilder sectionText = new StringBuilder();
 128:   
 129:   
 130:   
 131:          sectionText.Append("<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\">");
 132:   
 133:          sectionText.Append("<col style=\"white-space:nowrap\" align=\"right\" valign=\"top\" />");
 134:   
 135:          sectionText.Append("<col style=\"white-space:nowrap\" valign=\"top\" />");
 136:   
 137:   
 138:   
 139:          // we will give them absolute URL's
 140:   
 141:          MediaUrlOptions o = new MediaUrlOptions { AbsolutePath = true };
 142:   
 143:   
 144:   
 145:          // Get the path of the media item using it's path
 146:   
 147:          o.UseItemPath = true;
 148:   
 149:          sectionText.Append("<tr><td>Url by Path:</td><td>");
 150:   
 151:          sectionText.AppendFormat("<input class=\"scEditorHeaderQuickInfoInput\" readonly=\"readonly\" onclick=\"javascript:this.select();return false\" value=\"{0}\"/>", MediaManager.GetMediaUrl(mediaItem, o));
 152:   
 153:          sectionText.Append("</td></tr>");
 154:   
 155:   
 156:   
 157:          // Get the path of the media item using it's ID
 158:   
 159:          o.UseItemPath = false;
 160:   
 161:          sectionText.Append("<tr><td>Url by ID:</td><td>");
 162:   
 163:          sectionText.AppendFormat("<input class=\"scEditorHeaderQuickInfoInput\" readonly=\"readonly\" onclick=\"javascript:this.select();return false\" value=\"{0}\"/>", MediaManager.GetMediaUrl(mediaItem, o));
 164:   
 165:          sectionText.Append("</td></tr>");
 166:   
 167:   
 168:   
 169:          // is it File or DB media?
 170:   
 171:          sectionText.Append("<tr><td>Media Location:</td><td>");
 172:   
 173:          sectionText.Append(mediaItem.FileBased ? "File System" : "Database");
 174:   
 175:          sectionText.Append("</td></tr>");
 176:   
 177:   
 178:   
 179:          sectionText.Append("</table>");
 180:   
 181:   
 182:   
 183:          args.EditorFormatter.AddLiteralControl(args.Parent, sectionText.ToString());
 184:   
 185:      }
 186:   
 187:  }
You will need also to modify a pipeline. I would suggest creating a ShowMediaInfo.config in the /App_Config/Include directory with the following:


   1:  <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
   2:   
   3:    <sitecore>
   4:   
   5:      <pipelines>
   6:   
   7:        <renderContentEditor>
   8:   
   9:          <processor patch:before="processor[@type='Sitecore.Shell.Applications.ContentEditor.Pipelines.RenderContentEditor.RenderSkinedContentEditor, Sitecore.Client']"
  10:   
  11:                     type="NAMESPACE.ShowMediaInfo, ASSEMBLY" />
  12:   
  13:        </renderContentEditor>
  14:   
  15:      </pipelines>
  16:   
  17:    </sitecore>
  18:   
  19:  </configuration>

The idea for this was based on some code that a colleague of mine at Hedgehog Development had written.
Author:- Sean Kearney
Source:- http://seankearney.com/2010/08/default.aspx

Visual Studio Projects and Sitecore

This is a topic that I've been meaning to cover for some time now, but it is this post by John West that pushed me to do it sooner rather than later.
There are basically two ways of working with Sitecore.
  1. Your solution, and code, is fully immersed in the Sitecore web site.
  2. Your solution, and code, is outside of Sitecore's web site and you use some post build process to deploy.
John's post, and Sitecore documents, suggests that you go with option 1. I, however, do not agree that this is the right way to go. I feel that my code should not be mixed in with over 6,000 of Sitecore's files. Here are some reasons:
  1. The most important advantage is a clear understanding of the ownership of files in the solution. Everything checked into source control is explicitly owned by the solution being developed. All other files are owned by Sitecore or a third party package installed in Sitecore.
  2. I want to be able to distinguish my files from Sitecore's just by looking on the file system.
  3. If I need to ship the code to my client I simply want to zip up my 'workspace' and not have to wade through out-of-the box Sitecore files.
  4. I want my development environment to be as close as possible to a production environment. This means no .cs files in my web root
I've been working outside of the web root for three years now and wouldn't consider it being any other way. In fact, I am always wondering why you would want to work out of the web root as Sitecore suggests. I spoke to a client recently, while proving support for Team Development for Sitecore, and their answer was simply, "we didn't know better." That isn't acceptable.
Here is the way I work and highly suggest you work as well.
  1. Use IIS and configure Sitecore somewhere other than C:\[Workspace]\[Client]\trunk\. For example, C:\Sitecore\[Client]\Website
  2. Create your Visual Studio solution (and projects) outside of the web root. i.e. C:\[Workspace]\[Client]\trunk\ClientWebsite.sln
  3. Add references to any Sitecore assemblies as needed. Make sure to set "Copy Local" to false as John West suggests.
  4. Use a post build step to copy the output of your compiled Web Application project to the location specified in step 1. Or, better yet, use Team Development for Sitecore to handle the deployment for you.
  5. To debug, you will need to make a change to the Web Application project. On the 'Web' tab of the properties for your Web Application project you should choose the "Use Custom Web Server" option and enter in your development Sitecore URL. Once this setting has been specified you can now press F5 to build your project and debug normally. This may require some IIS components to be enabled, depending on your system. This will also work for IIS running on a remote machine (and virtual machines) as long as remote debugging components are installed on the remote machine.
Taking this one step further, you NEED to be using source control and automated builds in your development. Continuous Integration is also a good practice and possible using Team Development for Sitecore! Cost shouldn't be an excuse either as there are free tools out there to help you with this!
We, at Hedgehog Development, have done a good number of Sitecore sites this way and we do consider this a best practice. We are able to bring new developers onto a project in minutes and can roll out builds effortlessly.
I would love to get some feedback on this. Please let me know if you love working out of the web root as Sitecore suggests.
Author :- Sean Kearney
Source:- http://seankearney.com/2010/10/default.aspx