Showing posts with label TDS. Show all posts
Showing posts with label TDS. Show all posts

Friday, 31 January 2020

TDS Model Inheritance

Team Development for Sitecore Model Inheritance

For a long time now I have been trying to find a way to have TDS models inherit across the Helix architecture.

I found this link on StackOverflow:

https://stackoverflow.com/questions/31711197/sitecore-tds-multi-project-properties-base-template-reference-not-working-for-me

And thought it worth re-posting - Thanks to Rohan for figuring out how to do this!

All you have to do is to update Helpers.tt in the TDS project that needs to inherit base, as follows:


public static string GetNamespace(string defaultNamespace, SitecoreItem item, bool includeGlobal = false)
{
    List namespaceSegments = new List();
    // add the following line
    namespaceSegments.Add(!item.ReferencedItem ? defaultNamespace : "[BaseProjectNameSpace]");
    // remove this line - namespaceSegments.Add(defaultNamespace);
    namespaceSegments.Add(item.Namespace);
    string @namespace = AsNamespace(namespaceSegments); // use an extension method in the supporting assembly

    return (includeGlobal ? string.Concat("global::", @namespace) : @namespace).Replace(".sitecore.templates", "").Replace("_", "");
} 

Make sure that you replace the above [BaseProjectNameSpace] with your base projects namespace. 

Also make sure you update the Multi-Project  properties for your TDS project so that it references the base project:



Thursday, 15 October 2015

Extending TDS glass entity generation

One of the really cool features of Hedeghog's TDS (Team Developer for Sitecore - https://www.hhogdev.com/products/team-development-for-sitecore/overview.aspx) is that it can create Sitecore Glass entities automatically, when you synchronize specific portions of the Sitecore tree.  

One of the issues I came across was that when it creates properties for Sitecore link and list fields like DropLink and TreeListEx; it uses GUIDs rather than the entity in question.  So how do you get the code generation templates to link to the entity rather than to a GUID?

There is a really simple fix that involves 4 steps.


Let's assume that you have an entity called Product Filter which has a TreeListEx field, which references a list of Brand items.
  1. In the Sitecore core database navigate to the Field Types folder under system and create a copy of the TreeListEx field naming it something like Brand TreeListEx. 

    N.B. I also create a new folder to hold all my Entity Types so that they are easy to find when editing a template:


  2. In the template that uses the field; change the type to be Brand TreeListEx (or whatever you called it).

  3. In Visual Studio navigate to the TDS project that contains the code generation templates. 

    N.B. This is probably your Sitecore templates project. 

    Open up the code generation template for the glass items - in my code this was called glassv3item.tt.  Scroll down the script until you find the following method:

    public static string GetGlassFieldType(SitecoreField field)
    
    Locate the switch statement add the following on a new line:
    case "brand treelistex":
         return "IEnumerable<Brand>";
    N.B. The text in the case statement must be lowercase and must exactly match the name of the newly created field in the core database.

    N.B Always use IEnumerable for collections.

    N.B. For a single item reference field like a DropLink; change the return part to be something like:

    return "Brand";
  4. Now synchronize the Sitecore items project so that the Sitecore Glass code generation is redone, and you should then be good to go.