/// <summary> /// Renders scripts and CSS tags for /page/url.css and /page/url.js if those files exist /// </summary> /// <param name="helper"></param> /// <returns></returns> public static HtmlString RenderPageIncludes(this IHtmlHelper helper) { if (helper is null) { throw new ArgumentNullException(nameof(helper)); } string url = helper.ViewContext.HttpContext.Request.Path.ToString().Trim('/'); if (string.IsNullOrWhiteSpace(url)) { return(new HtmlString("")); } JavascriptTag jsTag = helper.GenerateJsTag(url); CssTag cssTag = helper.GenerateCssTag(url); string toReturn = string.Empty; if (jsTag.Exists) { toReturn += jsTag.ToString() + Environment.NewLine; } if (cssTag.Exists) { toReturn += cssTag.ToString() + Environment.NewLine; } return(new HtmlString(toReturn)); }
/// <summary> /// Adds the given filenames to the back end list of CSS files to find and include in the layout /// </summary> /// <param name="helper">The current HtmlHelper from the calling context</param> /// <param name="fileNames">A list of the filenames to add to the back end list of CSS files</param> public static void IncludeCSS(this IHtmlHelper helper, params string[] fileNames) { if (fileNames is null) { throw new ArgumentNullException(nameof(fileNames)); } string version = DateTime.Now.ToString("yyyyMMddhhmm", CultureInfo.CurrentCulture); foreach (string resourceName in fileNames) { CssTag tag = helper.GenerateCssTag(resourceName); CssTag extentionTag = helper.GenerateCssTag($"{resourceName}.extension"); helper.AddResource(tag.ToString()); if (extentionTag.Exists) { helper.AddResource(extentionTag.ToString()); } } }