Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Code Generated using Sitecore Rocks
    primarykey
    data
    text
    <p>I have just started exploring code generation using Sitecore Rocks. I found this question on this topic <a href="https://stackoverflow.com/a/18955719/468718">here</a> and solved the code generating <a href="http://www.harshbaid.in/2013/09/23/code-generation-using-sitecore-rocks-and-visual-studio/" rel="nofollow noreferrer">detailed here</a> however I could not find any documentation or blog on how to use the generated code.</p> <p>Currently I have coded to get the Sitecore Item using <code>GetItem</code> method in Sitecore Api and then contruct the DataTemplate class by passing Sitecore <code>Item</code> in the constructor. I have provided code in below:</p> <p><strong>User Control property logic:</strong></p> <pre><code> SiteSettings _siteSettings; public SiteSettings SiteLevelSettings { get { return _siteSettings = _siteSettings ?? CommonHelper.GetContextItem&lt;SiteSettings&gt;(Constant.ItemIDs.SiteSettings); } } </code></pre> <p><strong>Item Id <code>Constant</code> class</strong></p> <pre><code> public static class ItemIDs { public static readonly string SiteSettings = "{SOME GUID}"; } </code></pre> <p><strong>Get Item helper logic</strong></p> <pre><code> using Sc = Sitecore; public static T GetContextItem&lt;T&gt;(string sitecoreItemId = "") where T : class { T cxtItem = default(T); try { Sc.Data.Items.Item item = default(Sc.Data.Items.Item); if (string.IsNullOrWhiteSpace(sitecoreItemId)) item = Sc.Context.Item; else item = Sc.Context.Database.GetItem(new Sc.Data.ID(Guid.Parse(sitecoreItemId))); if (item != null) { cxtItem = Activator.CreateInstance(typeof(T), new object[] { item }) as T; } } catch (Exception ex) { Sc.Diagnostics.Log.Error("Error in GetContextItem&lt;T&gt;() where T : class", ex); } return cxtItem; } </code></pre> <p><strong>This is the interface <code>ISiteSettings</code> for <code>SiteSettings</code> class</strong></p> <pre><code>public interface ISiteSettings : IStandardTemplate { ImageField HeaderLogo { get; } RichTextField CopyrightContent { get; } DroptreeField HeaderNavigation { get; } DroptreeField FooterNavigationBottom { get; } DroptreeField FooterNavigationLeft { get; } DroptreeField FooterNavigationMiddle { get; } DroptreeField FooterNavigationRight { get; } DroptreeField FooterNavigationLogos { get; } } </code></pre> <p><strong>Here is the actual SiteSettings class</strong> <em>(code excerpts here)</em></p> <pre><code>public partial class SiteSettings : TemplateBase, ISiteSettings { [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Sitecore Code Generator", "1.0.0.0")] public Sitecore.Data.Items.Item InnerItem { get; set; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Sitecore Code Generator", "1.0.0.0")] public SiteSettings(Sitecore.Data.Items.Item item) // Constructor { this.InnerItem = item; } } </code></pre> <p>Question are: </p> <ol> <li>Is this the correct way to use Code Generated using Sitecore Rocks ?</li> <li>Any other better code generation strategy are there for Sitecore Cms solution ?</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload