/// <summary> /// Display module content on a page. /// </summary> /// <param name="helper">The html helper to render the content</param> /// <param name="options">The content display options</param> /// <returns>The content</returns> public static IHtmlString Content(this HtmlHelper helper, DisplayOptions options) { var controller = GetController(helper, options.Controller, options.Action); if (controller != null) { var getContentEvent = new GetContentEvent(helper, options); StrixPlatform.RaiseEvent(getContentEvent); if (getContentEvent.Result != null) { return getContentEvent.Result; } } return new HtmlString(options.DefaultText); }
/// <summary> /// Registers custom content used on a custom page. /// </summary> /// <param name="helper">The html helper to use</param> /// <param name="options">The options of the content</param> /// <returns>The content locator for this url</returns> public static ContentLocator RegisterUrl(HtmlHelper helper, DisplayOptions options) { return Registrator.RegisterUrl(helper, options); }
public ContentLocator RegisterUrl(HtmlHelper helper, DisplayOptions options) { var view = helper.ViewContext.View as RazorView; string viewPath = view.ViewPath.ToLower(); if (viewPath.Contains("/index.cshtml")) { viewPath = viewPath.Replace("/index.cshtml", string.Empty); } var pageUrl = viewPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault(); var locator = _contentLocators.FirstOrDefault(l => l.PageUrl == pageUrl && (options.Url != null ? options.Url.ToLower() == l.ContentUrl : l.ContentUrl == null)); if (locator == null) { locator = new ContentLocator { ContentUrl = options.Url != null ? options.Url.ToLower() : null, PageUrl = pageUrl.ToLower() }; _contentLocators.Add(locator); } return locator; }
/// <summary> /// Initializes a new instance of the <see cref="GetContentEvent"/> class. /// </summary> /// <param name="helper">The HtmlHelper used</param> /// <param name="options">The display options passed to the content helper</param> public GetContentEvent(HtmlHelper helper, DisplayOptions options) { this.Helper = helper; this.Options = options; }