Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Component Link in Page Metadata for DXA
using System.Globalization;
using Sdl.Web.Common.Models;
namespace Models
{
public class PageViewModel : PageModel
{
private SecurityMessage message;
Provide provider = new Provider();
public PageViewModel(string id) : base(id)
{
}
[SemanticProperty(PropertyName = "securityMessage")]
public SecurityMessage SecurityMessage { get; set; }
public bool HasSecurityMessage => SecurityMessage != null;
public SecurityMessage Message
{
get
{
if (HasSecurityMessage)
{
SecurityMessage model = provider.GetSecurityMessage(SecurityMessage.Id);
return model;
}
return message;
}
set { message = value; }
}
}
}
namespace Providers
{
public class Provider
{
#region Veriable
private IContentProvider _contentProvider;
#endregion
#region Properties
protected IContentProvider ContentProvider
{
get { return _contentProvider ?? (_contentProvider = SiteConfiguration.ContentProvider); }
set { _contentProvider = value; }
}
/// <summary>
/// Read and Return the Security message
/// </summary>
/// <param name="securityMessageId"></param>
/// <returns></returns>
public SecurityMessage GetSecurityMessage(string securityMessageId)
{
try
{
string presentationId = securityMessageId + "-" + SiteLabelConfiguration.TcmUriOfDynamicTemplateForMetadata;
SecurityMessage model = ContentProvider.GetEntityModel(presentationId, WebRequestContext.Localization) as SecurityMessage;
return model;
}
catch (Exception ex)
{
throw new DxaException("Error while Gettng Dynamic Tile Component", ex);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment