Amending DXA JSON

January 18th, 2018 | Posted by Robert Curlette in DXA - (0 Comments)

Sometimes you may wish to add additional content into the default DXA JSON content that is published to the Broker that are not part of the default Component Fields. In my situation I would like to have fields from the Page and Structure Group Metadata available in my DXA view. While using DXA 1.7 there is no out of the box, or ‘accelerated’, way to do this. My idea is to create an additional C# TBB, and in that access the DXA JSON and also add a field to it. The advantage to this approach is that the additional field will be seen by the DXA runtime as a Page Metadata field, and therefore serialized and available to us in the View without doing anything special on the DXA Frontend Webapp.

In this post I will share a sample app I used to access the DXA JSON and add an additional property into the MetadataFields collection. It was quite tricky to get this code to work, as we need to use the ‘dynamic’ type in C#, and this is without intellisense, so finding the appropriate methods and properties to use was a bit of a challenge. You will need to add the Newtonsoft JSON library from Nuget to get the code to work.

In a future article I will share more about the C# TBB that uses this code. The dxa.json file is the output of the Generate Dynamic Page (DXA) TBB form Template Builder. Also, in the code below, I only show an example for a text field, and I also do not product the JSON for XPM – as I have no intention of using XPM on these ‘fake’ Page Metadata fields.

using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using System;

namespace temp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string text = System.IO.File.ReadAllText(@"C:\RC\dxa.json");
            dynamic jsonObject = JObject.Parse(text);
            dynamic meta = jsonObject.MetadataFields;

            dynamic zone = new JObject();
            zone.Name = "zone";

            List values = new List()
            {
               "value"
            };

            dynamic array = JArray.FromObject(values);
            zone.Values = array;
            zone.FieldType = 0;  // text type, need to change if other field type

            // title is a mandatory metadata field on the Page
            meta.Property("title").AddAfterSelf(new JProperty("zone", zone));

            Console.ReadLine();
        }
    }
}

DXA 1.7 includes Template Building Blocks that help us publish content in JSON format to the Tridion Broker database. One of these Template Building Blocks is the GenerateSitemap.tbb that publishes all Pages and Structure Groups from your entire website as 1 JSON file. You might think this sounds great – and it really is – one great big file! However, if you have thousands of Pages and hundreds of Structure Groups, you might just be interested to publish the Structure Group info and Index pages in the Navigation JSON file. In this short post I’ll share the code I used to get started.  If this is your first time hacking the DXA Template Building Blocks, you might want to check out my post here on how to get started compiling the DXA TBBs.

The idea here is to create a new TBB, GenerateNavigation tbb, that publishes just the Structure Groups and index pages.

I’ve re-used the entire GenerateSitempa.tbb file and just modified one of the methods.

Here is my new modified method and also the call to it.

 

public override void Transform(Engine engine, Package package)
{
    Initialize(engine, package);

    _config = GetNavigationConfiguration(GetComponent());
   
    SitemapItem sitemap = GenerateStructureGroupNavigation(Publication.RootStructureGroup, true);

    string sitemapJson = JsonSerialize(sitemap);

    package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Text, sitemapJson));
}

 

private SitemapItem GenerateStructureGroupNavigation(StructureGroup structureGroup, bool structureGroupsOnly)
{
    SitemapItem result = new SitemapItem
    {
        Id = structureGroup.Id,
        Title = GetNavigationTitle(structureGroup),
        Url = System.Web.HttpUtility.UrlDecode(structureGroup.PublishLocationUrl),
        Type = ItemType.StructureGroup.ToString(),
        Visible = IsVisible(structureGroup.Title)
    };

   
    foreach (RepositoryLocalObject item in structureGroup.GetItems().Where(i => !i.Title.StartsWith("_")).OrderBy(i => i.Title))
    {
        SitemapItem childSitemapItem = null;
        Page page = item as Page;
        if (page != null)
        {
            if (page.FileName == "index")  // Add pages with the name index - APA Custom
            {
                if (!IsPublished(page))
                {
                    continue;
                }

                childSitemapItem = new SitemapItem
                {
                    Id = page.Id,
                    Title = GetNavigationTitle(page),
                    Url = GetUrl(page),
                    Type = ItemType.Page.ToString(),
                    PublishedDate = GetPublishedDate(page, Engine.PublishingContext.TargetType),
                    Visible = IsVisible(page.Title)
                };
            }
        }
        else
        {
            childSitemapItem = GenerateStructureGroupNavigation((StructureGroup)item, true);
        }
        if(childSitemapItem != null)
        {
            result.Items.Add(childSitemapItem);
        }
    }
   
    return result;
}

In this article I’ll discuss the process of downloading and compiling the Default DXA TBBs, and then we can add our new TBB to the default DXA project.  You might want to do this so you can add another TBB into the DXA project, or to modify one of the existing ones.  However, the DXA team would like to get your updates as a Pull Request so they can make the existing ones even better.

Modifying the Default DXA TBBs

1. Download the sources (with the correct version selected) from here: https://github.com/sdl/dxa-content-management

2. Open the solution and look at the Properties, then Build Events. There is a post-build event with the following:
“C:\Program Files (x86)\Microsoft\ILMerge\ILMerge.exe” ^
/out:Sdl.Web.Tridion.Templates.merged.dll ^
/targetplatform:v4 ^
/lib:C:\_references\cm-8.1 ^
Sdl.Web.Tridion.Templates.dll DD4T.ContentModel.Contracts.dll DD4T.ContentModel.dll DD4T.Serialization.dll DD4T.Templates.Base.dll Newtonsoft.Json.dll /log

3. Check if you have ILMerge.exe in the folder C:\Program Files (x86)\Microsoft\ILMerge\ILMerge.exe. If not, then download here: https://www.microsoft.com/en-us/download/details.aspx?id=17630

4. Copy the DLLs from the Tridion/bin/client folder to a folder on your local drive. I prefer to keep the references as part of the project. For example, I use: C:\RC\dxa-tbbs-1.7\dxa-content-management-release-1.7\references

All DLLs are required, even the ECL ones, and they’re all listed on the README here: https://github.com/sdl/dxa-content-management. If you don’t have ECL installed, you’ll need to install it at least on your Dev server to get the DLLs. You can use the Add/Remove Programs and ‘Change’ option to add the feature. Restart required, because the GUI will complain after you install the ECL without a restart.  Also, The DLLs after the path are expected to be found in the /bin/debug folder of the project.

5. Build

Potential errors:
1. Error code 3 – This means Visual Studio cannot find ILMerge.exe
2. Error code 1 – It cannot find the DLLs folder specified in the post-build script

Tips:
– Use the /log switch in the post-build command to write the output to the ‘Output’ window for easier debugging

Happy hacking!

DXA and the SDL.Web.Tridion.dll

September 28th, 2017 | Posted by Robert Curlette in DXA - (0 Comments)

When creating a new DXA (1.7) Web Application we can use DXA Core sample website to get started or we can start fresh, and build it from ground up using the NuGet packages.  In a recent project we wanted to start fresh, only using the framework itself and not any of the samples provided OOTB.  While some may say we lose the ‘acceleration’ by taking this path, others could argue that in most client applications they prefer to have a clean solution where they know what all the code does, and why, and have no extra stuff that is not needed or used inside.  So, anyways, we decided to take the high road and start from a ‘file, new project’ approach.  It hasn’t been easy, but it’s been real.

While making the new project you will have almost everything you need – except for one very important and not included DLL – the SDL.Web.Tridion.dll file.  This is referenced from the Unity IoC container…and you can see it in the Unity.config file.  It is not referenced in the project references.  When you don’t have this file in the /bin folder, you will get the following error message:

The type name or alias DefaultCacheProvider could not be resolved. 
Please check your configuration file and verify this type name.

The solution is quite simple, but can be deceiving.  The DXA Sample Project .csproj file includes a very important command to tell the project to copy the DLL.

 <Target Name="BeforeBuild">
 <CallTarget Targets="CopyDxaFrameworkLibsToOutput" />
 </Target>

In your own .csproj file, copy the above config anywhere on the top level.  I placed mine before the final closing </Project> tag.  Now, re-open the project in Visual Studio and build, and you should see the friendly SDL.Web.Tridion.dll file in the bin folder and your website will be happy again.

2016 has been a crazy year – let’s just agree on this and not get into the details!  But, 2016 also did have some positive moments, especially in the Tridion community. Here I hope to highlight some of the positive contributions the community has made this year and hope that next year we will see continued support for these amazing initiatives!

DXA

This year has been the year the DXA framework (formerly known as the SDL Tridion Reference Implementation) has made made some traction and we’ve seen increased usage in projects.   The DXA team recently released version 1.7 and if you’re curious to find out what has been added, fixed and improved in this version then please see the release notes here.

We can see that DXA has been very active from a number of areas, such as their github repository with 1465 commits (https://github.com/sdl/dxa-web-application-dotnet/commits/master) and 360 questions on the Tridion StackExchange forum (http://tridion.stackexchange.com/questions/tagged/dxa?sort=newest&pageSize=50)

One of the nice things about using DXA is the modules that play nicely with other SDL products, such as Experience Manager, Audience Manager, Media Manager and Context Expressions. If you’d like to download them for free, then the latest versions can be found here, https://github.com/sdl/dxa-modules/releases

The official documentation has some good content and can be used as a reference, https://docs.sdl.com/LiveContent/content/en-US/SDL%20DXA-v7/GUID-8173623D-D605-4962-AFBD-25D5F6DC6D93

And if you prefer online or classroom training, it’s now available from SDL for DXA too, http://training.sdl.com/services/education-certification/training-product/web-content-management/index-tab4.html

If you would like to build a small microsite with your team in a workshop setting, then you may be interested in the DXA Microsite workshop that I teach. It is a 4 day course where we go over all the basics and walk the team through building a microsite based on your requirements. It is taught both online and remote. If you’re interested, please contact me at robert.curlette@gmail.com and mention the DXA microsite workshop.

Alchemy

Alchemy is the framework that makes your editors and authors happy, and saves time for everyone using the Tridion CMS Editor interface. A full plugin GUI framework created by Alex Klock and supported by Content Bloom, this is the framework you’ll install in 2017 to impress your content authoring team. The only requirement is that you use Tridion 2013 or SDL Web 8.

Installing the framework takes minutes, thanks to the nice MSI install, and it’s a 1 time install on the CMS server. The installer can be downloaded from here, just need to register first,  https://www.alchemywebstore.com/ See how easy it is with this video from John Winter, http://www.tridiondeveloper.com/how-to-install-and-uninstall-alchemy-for-tridion-web

Alex Klock and Tanner Brine  presented Alchemy at the Tridion Developer Summit 2015 and the video can be seen here, http://2015.tridiondevelopersummit.com/2015/home/transmute-tridion-into-the-lean-green-content-management-machine-of-your-dreams-with-alchemy4tridion/

This year the Alchemy Webstore  saw a lot of nice improvements and is a really easy to use one-stop-shop for finding all your Alchemy community plugins. As of now, all plugins are free, and can be used in your project without worries. Several new plugins arrived this year, including ‘CommonKeyboardShortcuts’ (https://www.alchemywebstore.com/plugins/CommonKeyboardShortcuts), Save Close Publish Page, (https://www.alchemywebstore.com/plugins/Save-Close-Publish-Page), and Peek (https://www.alchemywebstore.com/plugins/Peek).

Another reason to use Alchemy is the excellent packaging model, with .A4T files, and easy drag-n-drop deployment of the plugins you write. So, if you haven’t given it a spin, please do so now.

And, if you’d like to watch some video tutorials to help get you started, check out the amazing Alchemy Code Dojo presented by John Winter here, where he builds an Alchemy plugin from scratch in front of a live audience, https://vimeo.com/170368377

In case you can’t get enough of John or videos, check out the excellent series below on creating an Alchemy plugin:

Creating an Alchemy Plugin: Step 1 – The tools, http://www.tridiondeveloper.com/creating-an-alchemy-plugin-step-1-the-tools

Creating an Alchemy Plugin 2: Sample project overview and refactoring, http://www.tridiondeveloper.com/creating-an-alchemy-video-2-sample-project-overview-and-refactoring

Creating an Alchemy Plugin 3: Ribbon Toolbar and Context Menu, http://www.tridiondeveloper.com/creating-an-alchemy-plugin-2-ribbon-toolbar-and-context-menu

Alchemy Training Video 4: Creating a Popup Window, http://www.tridiondeveloper.com/alchemy-training-video-4-creating-a-popup-window

Alchemy Training Video 5: Adding CSS and JavaScript to our Tridion Popup Window, http://www.tridiondeveloper.com/alchemy-training-video-5-adding-css-and-javascript-to-our-tridion-popup-window

If you would like a hands-on workshop or course on Alchemy, I am teaching a 2 day course online or onsite, and if interested please contact me at robert.curlette@gmail.com

Conferences

Finally, this year we saw 3 technical Tridion conference events, recognizing the appreciation of sharing knowledge in the Tridion (SDL Web) community and that meeting and discussing technical solutions in person is priceless.

The Tridion Developer Summit saw more than 140 Tridion developers and consultants get together in Amsterdam for another 2 days and over 20 great sessions and sharing. If you missed it, or would like to see a talk again, all videos are available online here, http://2016a.tridiondevelopersummit.com/2016/videos-tds/

The next TDS is taking place on 11-12 May 2017 in Amsterdam and promises to be filled with technical Tridion content and lots of sharing opportunities.  Registration will open in early January.  If you would like to attend or present, please contact me at robert.curlette@gmail.com

This year we saw the first India Tridion Developer Summit, and I was honored to present about the Alchemy Framework. It was very well organized and had more than 60 enthusiastic Tridion developers from across India attending. I really enjoyed meeting so many active Tridion implementors and discussing implementations with them over delicious Indian food. I wrote about my experience here, http://www.curlette.com/?p=1492 Great job for the organizers and a nice writeup by Pankaj Gaur here, https://pankajgaur83.wordpress.com/2016/02/11/highlights-sdl-web-8-dev-summit-at-india/

Just last month we had the SDL Connect event in San Francisco and it was filled with an amazing energy and spirit. Days 1 and Day 2 were mostly for the business and marketing professionals.   It was great connecting with former colleagues and meeting new people.  Highlights from day 1 are here, https://www.youtube.com/watch?v=SeRe95Q8nAM.  The best was saved for last, and on day 3 we had a day of technical Tridion sessions in the same flavor as TDS, including a great Product Roadmap presentation by Alvin Reyes, DXA session by Bart Koopman, Cache invalidation talk by Mihai, Alchemy talk by Tanner Brine, and I presented a talk about upgrading to Web 8. Overall the event was a lot of fun and I look forward to the next one.

DD4T

This year the DD4T framework continued to mature and we saw a 2.1 version released.  But, most importantly, a decision was made to merge DD4T and DXA into 1 version, and to be named ‘DXA 2.0’.  We expect to see a release of the love child of DXA and DD4T sometime in 2017.   You can read more about it from Nuno and Quirijn here, and from Pankaj about why it’s merging here.

Summary

2016 was a year that we saw the DXA and Alchemy frameworks mature and gain wider acceptance. This should be a bright spot for anyone working with Tridion and investing in improving their implementations. I hope next year will bring more opportunities for sharing, more conferences, more events, and most of all, more fun!

Sometimes when setting up Topology Manager you might want to rewind, undo everything, and start fresh.  After all, in version 8.1.1.1 the install is a combination of PowerShell scripts with various configuration options, authentication mechanisms, etc and it is likely to get something wrong, and you want to start all over.  If this is the case, I hope this article will help.  Below I have the output of my PowerShell console where I remove all the relevant Topology Manager pieces.  I also removed the Deployer and Discovery service, and at the end of the article I have those PowerShell scripts too, but from a separate window due to security rights.

The security rights for running and executing the Topology Manager powershell scripts can be confusing.  To run the below scripts, please go to the Windows Start screen in Windows Server 2012, search for PowerShell ISE, right click and select ‘Pin to Start’.  Then, right-click on it and select ‘Run as User’ and type in your own user params (assuming you are an Admin).  Also, your user account needs to be in the Windows Groups for Topology Manager (yes, these are new and yes it is important to be in these groups).  Now, you can run the scripts below.  To uninstall the Deployer and Discovery services, you need to run a new PowerShell window as Administrator.  Hope this helps!

PS C:\Users\rcurlette> Get-TtmMapping
CmEnvironmentId : Tridioncmsnd_landbdev2
PublicationId : tcm:0-11-1
EnvironmentPurpose : Dev
WebApplicationId : FooBuWebSite_RootWebApp
RelativeUrl : /
PrimaryMappedUrl : http://localhost:8020/
IsOffline : False
CdEnvironment : 
Id : Mapping1
ExtensionProperties : {}
PS C:\Users\rcurlette> Remove-TtmMapping
cmdlet Remove-TtmMapping at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
Id: Mapping1
PS C:\Users\rcurlette> Get-TtmWebApplication
ContextUrl : /
WebsiteId : FooBuWebSite
EnvironmentPurpose : Dev
CdEnvironment : 
ScopedRepositoryKeys : {}
Id : FooBuWebSite_RootWebApp
ExtensionProperties : {}
PS C:\Users\rcurlette> Remove-TtmWebApplication FooBuWebSite_RootWebApp
PS C:\Users\rcurlette> Get-TtmWebsite
BaseUrls : {http://localhost:8020}
CdEnvironmentId : WEBCMSND_ENV
EnvironmentPurpose : Dev
CdEnvironment : 
ScopedRepositoryKeys : {}
Id : FooBuWebSite
ExtensionProperties : {}
PS C:\Users\rcurlette> Remove-TtmWebsite FooBuWebSite
PS C:\Users\rcurlette> Get-TtmCdTopologyType
Name EnvironmentPurposes Id ExtensionProperties 
---- ------------------- -- ------------------- 
FooBu.org {Dev} FooBu_org {} 
Foo.org {Preview, Live, Test, Dev} Foo_org {}
PS C:\Users\rcurlette> Get-TtmCdTopology
CdTopologyTypeId : FooBu_org
Name : Local
Description : 
CdEnvironmentIds : {WEBCMSND_ENV}
CdEnvironments : {}
ScopedRepositoryKeys : {}
Id : Local
ExtensionProperties : {}
PS C:\Users\rcurlette> Remove-TtmCdTopology Local
PS C:\Users\rcurlette> Remove-TtmCdTopologyType FooBu_org
Remove-TtmCdTopologyType : Item of type 'CdTopologyTypeData' can not be deleted. It is used by Business Process Type with id 'tcm:11-23307-4096' in 
the Content Management environment with id 'Tridioncmsnd_landbdev2'.
At line:1 char:1
+ Remove-TtmCdTopologyType FooBu_org
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : NotSpecified: (Tridion.Topolog...logyTypeCommand:RemoveCdTopologyTypeCommand) [Remove-TtmCdTopologyType], DataServiceE 
 xception
 + FullyQualifiedErrorId : Tridion.TopologyManager.Automation.RemoveCdTopologyTypeCommand
PS C:\Users\rcurlette> Remove-TtmCdTopologyType FooBu_org
PS C:\Users\rcurlette> Get-TtmCmEnvironment
CoreServiceRootUrl : net.tcp://localhost:2660
WebsiteRootUrl : http://WEBCMSND.apa.org:81
CoreServiceCredentials : "AuthenticationType":"Windows", "UserName":"Foo\mts_svc", "Password":"b1o$50Ming"
Id : Tridioncmsnd_landbdev2
ExtensionProperties : {}
PS C:\Users\rcurlette> Get-TtmCdEnvironment
EnvironmentPurpose : Dev
DiscoveryEndpointUrl : http://localhost:8082/discovery.svc
Credentials : "AuthenticationType":"Anonymous"
IsOffline : False
ScopedRepositoryKeys : {}
Id : WEBCMSND_ENV
ExtensionProperties : {}
PS C:\Users\rcurlette> Remove-TtmCdEnvironment WEBCMSND_ENV

Removing the Deployer and Discovery Services

Run PowerShell as Administrator user

PS C:\SDL\Web\discovery\bin> .\uninstallService.ps1
 Stopping service 'SDLWebDiscoveryService'...
SERVICE_NAME: SDLWebDiscoveryService
 TYPE : 10 WIN32_OWN_PROCESS
 STATE : 3 STOP_PENDING
 (NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
 WIN32_EXIT_CODE : 0 (0x0)
 SERVICE_EXIT_CODE : 0 (0x0)
 CHECKPOINT : 0x2
 WAIT_HINT : 0xbb8
 Service 'SDLWebDiscoveryService' is stopped.
 Removing service 'SDLWebDiscoveryService'...
 [SC] DeleteService SUCCESS
 Service 'SDLWebDiscoveryService' successfully removed.
PS C:\SDL\Web\discovery\bin> cd ..
PS C:\SDL\Web\discovery> cd ..
PS C:\SDL\Web> cd .\deployer
PS C:\SDL\Web\deployer> cd bin
PS C:\SDL\Web\deployer\bin> .\uninstallService.ps1
 Stopping service 'SDLWebDeployerService'...
 [SC] ControlService FAILED 1062:
The service has not been started.
Service 'SDLWebDeployerService' is stopped.
 Removing service 'SDLWebDeployerService'...
 [SC] DeleteService SUCCESS
 Service 'SDLWebDeployerService' successfully removed.
PS C:\SDL\Web\deployer\bin>

SDL Web to be Renamed?

April 1st, 2016 | Posted by Robert Curlette in AprilFools - (0 Comments)

According to community insiders, SDL will rename its latest product, Web 8.  The flagship product includes Tridion, the CMS platform that is the choice of multi national companies across the globe.   In the beginning the product was known as Tridion DialogServer but eventually the company shortened the product name to Tridion, the same as the company name.  However, recently the name got even shorter, to just ‘Web’, or ‘SDL Web 8’ for the longer version.

Many people found the name ‘Web’ too ambiguous and confusing.  This Wikipedia article suggests that ‘Web’ could refer to “Arachnology, Anatomy/Biology, Computing, Mathematics, Publications, Television, or Radio and film.”.  

Rumors in the Tridion community are that it will be renamed to SDL ‘World Wide Web 8’, and shortened to WWW8, or W38 for short.  The other name being considered was ‘Internet 8’, but they decided that was too broad.

The decision is still open for the next name of the flagship CMS product from SDL, formerly known as Tridion.  What do you think the new name should be?  Leave your feedback in the comments below.

powershell plus     Screen Shot 2016-03-21 at 16.58.40

Developing Alchemy extensions has the goal of improving the Tridion User Experience for Developers, Authors and Editors.  But, what about making it easier for us to develop Alchemy Plugins?  Peter Kjaer had us in mind when he developed the excellent Alchemy Powershell Plugins.  You only need 5 minutes to get started with these scripts and they will save you lots of time and no more dragging and dropping the Plugin after you build every time.

The plugin watched the /bin/debug folder of your Alchemy Visual Studio project and automagically sends the .a4t file to Tridion and updates the GUI.

Follow these easy steps to get it running:

If your server is connected to the Internet then you can get started with 1 easy command at the PowerShell Command Line from https://github.com/pkjaer/tridion-powershell-modules/blob/master/README.md:

wget “https://raw.githubusercontent.com/pkjaer/tridion-powershell-modules/master/Alchemy/Installation/Install.ps1” | iex

Otherwise, if your server is behind a firewall and unable to executre the wget command, have no fear, the quick manual install process is here!

1.  Download the Powershell scripts from https://github.com/pkjaer/tridion-powershell-modules (Download .zip button) or in a terminal type ‘git clone https://github.com/pkjaer/tridion-powershell-modules.git’

2.  Open the PowerShell Command Prompt or the PowerShell ISE and go to ‘Alchemy/Installation’.    Install the scripts with ‘.\Install-Local.ps1’.  If you use only the ‘Install.ps1’ script then it will require an Internet connection.

3.  Start the Alchemy Plugin Monitor script by typing  ‘Start-AlchemyPluginMonitor’

4.  Enter the folder of your plugin’s bin/debug folder

5.  Go into Visual Studio and build the project.  If you have the PowerShell ISE open, you will see the PowerShell script copying the .A4T file to Tridion.

 

Summary

Using the Alchemy Framework has many benefits when building Tridion GUI Extensions.  One of the strongest features in my opinion is the packaging of  files in an .A4T package, and the ease of deployment of the .A4T files with the Alchemy Webstore, Drag-n-Drop or PowerShell.  These PowerShell scripts from Peter Kjaer support and strengthen the Alchemy Development Tooling Pipeline, making our lives easier as Developers and help us bring the magic of Alchemy plugins to users faster than ever before.

This year the SDL Web Dev Summit India was hosted in Delhi and I had the opportunity to present about the Tridion Alchemy Framework.  For the presentation I ported to Alchemy an older custom ASP script to delete (and unlocalize) All Blueprint Children.  In this article I will highlight the process I used and include a link to the sourcecode.  I stil need to polish a few things before I add it to the Alchemy store, but please have a look at my code and hopefully it will help you in building your Alchemy plugins.

Screen Shot 2016-02-08 at 18.45.53

Here I will outline the steps I followed to write the plugin.  I won’t dive into too much detail, but I hope this will help you get started.

Prep work

Writing a plugin involves looking at some good code samples.  So, my first step was to download and install every Alchemy plugin and also every sourcecode repository that was available.

The latest version of the Alchemy VSIX Visual Studio Plugin has a nice Project Type called ‘Starter Plugin Project’. This creates a nice example with a button in the ribbon and also context menu. In my presentation I was able to go from File, New Project to having an Alchemy Plugin in my Tridion system in under 3 minutes.  The reason I like the starter project so much (aside form the fact it’s very easy and fast to use) is it has a great clean structure of the files and folders, and provides an excellent reference.

Writing the GUI

The GUI is now much easier to write and install than ever before (especially if you’ve done GUI Extensions!).  However, there is some rhyme and reason for a lot of the things in the Alchemy framework and I will try to highlight a few here.

1.  Create the Static folder.  This holds your Commands .js file (which is executed when you fire the GUI event, and the same one we used in older GUI Extensions).  Also in static you’ll have any .aspx popup files and css/js files your popup uses.   In Static I create a Commands folder.

2. Next create a new Alchemy GUI item, Alchemy Javascript Command
Screen Shot 2016-02-22 at 17.36.19

 

3.  In the .js file, I define a command name, ‘UnLocalizeAllCommand’ that is very important and will be used later.  I also borrowed some code from Mark Richardson’s ‘Real Time Publishing Stats’ plugin to open the popup .aspx file.  *Note – in this version your popup must be an .aspx file and not .html.  Otherwise, it will not be deployed to the views folder when you deploy the .a4t file.

4.  Under static, create a Views folder and in there the .aspx page for the popup.  The Javascript code to call the WebApi Controller (with CoreSevrice) was quite tricky to get correct.  You can see it here on Github

5.  Next is to Add the button to the GUI.  The context menu is added with ContextMenuUnlocalizeAll.cs and Ribbon is from RibbonToolbar.cs.

6.  Next we tell Alchemy what files to include for us with the ResourceGroupFiles.cs and PopupResourceGroup.cs files.

7.  With the PluginCommandSet.cs we specify the same command name we used in step 3.

8.  Now we could build and deploy the Alchemy Plugin and we should be able to see the items in the context menu and ribbon bar.  The last step is to add the functionality to do something.

9.  Create the controller, UnLocalizeController.cs,  in a new Controllers folder and make sure to reference the Core Service Client.  Here is where the main functionality is impemented.  Carefully look at the AlchemyRootPrefix attribute and also the Route attribute on the class.  These 2 parameters define how we access the service.

10.  Finally, build the project to create the .A4T file.  If you get annoyed with the alchemy popup window, disable it by opening your .csproj file (in Notepad++ you’ll need to run it with the Admin user) and follow my tip here to disable it for Dev.

11.  Drag and drop your .A4T file into the Tridion Alchemy GUI Admin and then refresh the GUI.  With a bit of luck and the right star alignment your new Alchemy Plugin should be working.  If not, use the browser’s JavaScript console to help debug any .js errors coming from the plugin.

Full Source Code is available here:  https://github.com/rcurlette/AlchemyUnlocalizeAllChildren/

Summary

I hope this article helped you understand the flow of building an Alchemy plugin and assists you in your plugin dev.  Please share your plugins on the Alchemy WebStore so we can all benefit from the community.  Special thanks to Pankaj Guar for inviting me to speak at the SDL Web Developer Summit India!  Big thanks to Content Bloom and Alex Klock for creating the Alchemy Framework and sharing with the world!

1SDL Web India Dev Summit - Group

1SDL Web India Dev Summit – Group

 

Starting an Alchemy plugin project is super easy. In this post I just want to mention a quick tip that will help you use the latest version of the framework for your Alchemy potions.

1. Download the Alchemy4Tridion Developer Pack (VSIX Visual Studio Project template). This gives us some really cool filetypes in the File, New dialog:

Screen Shot 2015-09-29 at 17.36.35

 

2. After creating a new project, go to the Nuget Package manager and search for ‘A4T’ and install the framework. This makes sure your Alchemy DLL is the latest, and also gives you the goodness of the Visual Studio templates.
Screen Shot 2015-09-29 at 17.37.30

 

3. Get a good clean example to follow. As of September, 2015 this is the CopyInfo example from Alex Klock for me. The Big Box of Samples is intended to be the ‘Unit Testing’ plugin for the Alchemy devs, so lots of goodies to be found there too!

 

Have you built an Alchemy plugin that is a good starting point? Leave a comment below with a link to the source code. Thanks!