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.
- 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;
}
Create the Strong-name and add it to the GAC using the gacutil.exe.
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>
Restart SDL Tridion services and COM+
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.