2

In SDL Tridion 2013 SP1, we were using Razor Mediator built-in property/function "IsSiteEditEnabled" in our Razor functions. Based on its value if IsSiteEditEnabled is true or false we were adding the script in the page layout to invoke the XPM button.

<script type='text/javascript' language='javascript' defer='defer' src='https://******/WebUI/Editors/SiteEdit/Views/Bootstrap/Bootstrap.aspx?mode=js' id='tridion.siteedit'></script>

Now we are upgrading to SDL web 8.5, my question is whether the same IsSiteEditEnabled Razor mediator built-in function will work for SDL web 8.5 also or is there any workaround to make it work in SDL Web 8.5.

Please Note: For Dreamweaver templates, we developed a custom TBB, to get the "EnableSiteEdit" property from Pub.Target, and as part of SDL Web 8.5, I have updated the TBB code as mentioned here and its working fine for Dreamweaver templates. I'm facing issue with the Razor templates.

Please let me know if you have any inputs on this.

3

AFAIK -

Question1: my question is whether the same IsSiteEditEnabled Razor mediator built-in function will work for SDL web 8.5

Answers: Yes. if you are using the legacy publishing target and without new Topology manager setup, IsSiteEditEnabled reading the value from LoadApplicationData for the Publication Target.

Current IsSiteEditEnabled function in Razor mediator:

public bool IsSiteEditEnabled
        {
            get
            {
                if (!_cachedIsSiteEditEnabled)
                {
                    if (_engine.PublishingContext.PublicationTarget != null && _engine.PublishingContext.PublicationTarget.Id != TcmUri.UriNull)
                    {
                        ApplicationData data = _engine.PublishingContext.PublicationTarget.LoadApplicationData("SiteEdit");
                        if (data == null)
                        {
                            _cachedIsSiteEditEnabled = true;
                            return false;
                        }

                        XmlElement appData = data.GetAs<XmlElement>();
                        XmlNodeList nodes = appData.GetElementsByTagName("EnableSiteEdit");
                        if (nodes.Count > 0 && nodes[0].InnerText.Equals("true"))
                        {
                            _isSiteEditEnabled = true;
                        }
                    }
                    _cachedIsSiteEditEnabled = true;
                }
                return _isSiteEditEnabled;
            }
        }

Question2: is there any workaround to make it work in SDL Web 8.5

Answers: Yes. if you are using topology manager setup based on publication business process type and publishing target for staging discovery service registered with Preview Capability.

You can create the custom built-in template callable method to achieve this on your Razor template based on below code reference as you already aware and mentioned that link.

public static bool IsXpmEnabled(PublishingContext publishingContext)
        {
            if (publishingContext == null || publishingContext.PublicationTarget == null)
            {
                return false;
            }

            if (Session.ApiVersion.StartsWith("8."))
            {
                // We're going to use new properties which are only available in CM 8.1 and higher.
                // To avoid having to reference CM 8.1 APIs (which won't bind on CM 7.1), we use dynamic types here.
                dynamic pubContext = publishingContext;
                dynamic targetType = pubContext.TargetType;
                if (targetType != null && targetType.BusinessProcessType != null)
                {
                    // New-style publishing
                    Publication contextPublication = (Publication) ((RepositoryLocalObject) publishingContext.ResolvedItem.Item).ContextRepository;
                    return targetType.IsPreviewCapable(contextPublication);
                }
            }

            return IsPublicationTargetXpmEnabled(publishingContext.PublicationTarget);
        }

Update:

To create and use your Custom Dreamweaver Functions from a Razor Mediator.

  1. Create a custom class in C# using the TOM.NET API based on ITemplate and IFunctionSource
    [TemplateCallable]
        public bool IsXpmEnabled()
        {
            if (mEngine.PublishingContext == null || mEngine.PublishingContext.PublicationTarget == null)
            {
                return false;
            }

            if (Session.ApiVersion.StartsWith("8."))
            {
                // We're going to use new properties which are only available in CM 8.1 and higher.
                // To avoid having to reference CM 8.1 APIs (which won't bind on CM 7.1), we use dynamic types here.
                dynamic pubContext = mEngine.PublishingContext;
                dynamic targetType = pubContext.TargetType;
                if (targetType != null && targetType.BusinessProcessType != null)
                {
                    // New-style publishing
                    Publication contextPublication = (Publication)((RepositoryLocalObject)mEngine.PublishingContext.ResolvedItem.Item).ContextRepository;
                    return targetType.IsPreviewCapable(contextPublication);
                }
            }

            return false;
        }

  1. Create the Strong-name and add it to the GAC using the gacutil.exe.

  2. Edit your environment Tridion.ContentManager.config and find the element and inside it, the element. Add your class dll reference.

    <tridion.templating>
        <functionSources>
            <functionSource type="YourCompany.Tridion.Templating.YourCustomClassExtensions" assembly="MyCustomClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ddfc8957d6e5ee6b" />
        </functionSources>
    </tridion.templating>
  1. Restart SDL Tridion services and COM+

  2. In your TBB Razor template, you can call your template callable function as below

    @{ 
         var dw = new YourCompany.Tridion.Templating.YourCustomClassExtensions();
         dw.Initialize(TridionHelper.Engine, TridionHelper.Package);  
    }
    
    @if(dw.IsXpmEnabled() 
    {
      //TO DO Add the script to render the xpm button
    }
    

I hope it helps.

  • @Mohammed Ali - Updated my answer to included the steps to create the template callable function for your reference – Velmurugan May 3 '18 at 8:10
  • Thanks Velmurugan. These detailed steps are useful, if we want to use the Template callable method in Razor. I guess these steps are similar to how we use the Template callable method in Dremweaver templates. Thanks again for the update. – Mohammed Ali May 4 '18 at 14:08
  • Please accept the answer if it's helped to resolved your issue – Velmurugan Mar 28 at 11:20
2

This is somewhat related to my question here How to check publishing or rendering context using TOM.NET in the new publishing framework since you are dealing with publishing context. See the accepted answer there, but in short:

With regards to publishing context, the same logic can still be used as before; the new publishing framework uses Topology Manager Mappings instead of Publication Targets, but you will find that there is still a PublicationTarget set in the API (a so-called emulated Publication Target). This is done for backward compatibility purposes.

If you want to avoid using (now deprecated) Publication Targets in your code, you can use Engine.PublishingContext.TargetType instead.

In DXA (up to version 1.6) we were supporting both SDL Tridion 2013 SP1 and SDL Web 8, so there we had to use two different ways of detecting if XPM (SiteEdit) was enabled or not.

For the new publishing framework you can use:

targetType.IsPreviewCapable(contextPublication);

While on the deprecated legacy publishing setup you would check the application data of the PublicationTarget

See the following code we used in our TBBs which shows how you can manage that:

https://github.com/sdl/dxa-content-management/blob/release/1.6/Sdl.Web.Tridion.Templates/Common/Utility.cs#L42

Note that this code works under the assumption that Web 8 will always use the new publishing framework and not the deprecated legacy publishing setup.

  • Thank you Bart. I already made the changes to the TBB code as part of SDL Web 8.5 with Topology way of publishing. But this TBB is not being used in my Razor Mediator templates. In Razor Mediator Razor functions Tbb, we used the built-in property "IsSiteEditEnabled". So I want to update the Razor functions code as part of SDL Web 8.5 with Topology way of publishing. – Mohammed Ali May 1 '18 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.