Guest User

Untitled

a guest
Dec 13th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. namespace Corlate.Feature.Configurations.Models
  2. {
  3. using Corlate.Foundation.Common.Utilities;
  4. using Sitecore.Data;
  5. using Sitecore.Data.Items;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Text;
  9.  
  10. /// <summary>
  11. /// Defines the <see cref="PageSettings" />
  12. /// </summary>
  13. public class PageSettings : CustomItem
  14. {
  15. /// <summary>
  16. /// Initializes a new instance of the <see cref="PageSettings"/> class.
  17. /// </summary>
  18. /// <param name="innerItem">The <see cref="Item"/></param>
  19. public PageSettings(Item innerItem) : base(innerItem)
  20. {
  21. }
  22.  
  23. /// <summary>
  24. /// Gets the ThemeLibrariesInsideHeadTag
  25. /// </summary>
  26. public string ThemeLibrariesInsideHeadTag
  27. {
  28. get
  29. {
  30. return GetThemeLibraryReferences(References.Templates.PageSettings.Fields.ThemeLibrariesInsideHeadTag);
  31. }
  32. }
  33.  
  34. /// <summary>
  35. /// Gets the ThemeLibrariesInsideBodyTag
  36. /// </summary>
  37. public string ThemeLibrariesInsideBodyTag
  38. {
  39. get
  40. {
  41. return GetThemeLibraryReferences(References.Templates.PageSettings.Fields.ThemeLibrariesInsideBodyTag);
  42. }
  43. }
  44.  
  45. /// <summary>
  46. /// gets the html markup of references for all the selected theme libraries
  47. /// </summary>
  48. /// <param name="multilistFieldID"></param>
  49. /// <returns></returns>
  50. public string GetThemeLibraryReferences(ID multilistFieldID)
  51. {
  52. StringBuilder sbReferences = new StringBuilder(string.Empty);
  53.  
  54. try
  55. {
  56. IList<Item> selectedItems = SitecoreUtility.GetSelectedItemsInMultilistField(InnerItem, multilistFieldID);
  57. ThemeLibrary themeLibrary = null;
  58.  
  59. if (selectedItems != null && selectedItems.Count > 0)
  60. {
  61. foreach (Item item in selectedItems)
  62. {
  63. themeLibrary = new ThemeLibrary(item);
  64.  
  65. if (themeLibrary != null)
  66. {
  67. if (themeLibrary.IsStylesheet)
  68. {
  69. sbReferences.AppendLine("<link href=\"" + themeLibrary.FilePath + "\" rel=\"stylesheet\" />");
  70. }
  71. else
  72. {
  73. sbReferences.AppendLine("<script src=\"" + themeLibrary.FilePath + "\"></script>");
  74. }
  75. }
  76. }
  77. }
  78. }
  79. catch (Exception ex)
  80. {
  81. sbReferences = new StringBuilder(string.Empty);
  82. }
  83.  
  84. return Convert.ToString(sbReferences);
  85. }
  86. }
  87. }
Add Comment
Please, Sign In to add comment