#Cee Cee community

Error executing template "Designs/TwenteBranding/QueryPublisher/HashtagArticleQueryList.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at Dynamicweb.Content.ItemService.GetItemByPageId(Int32 pageId, Boolean draft, DateTime previewDate)
at TwenteBranding.Repository.Helpers.ItemHelper.<>c__DisplayClass27_0.b__0(Page y) in D:\agent_2\_work\78\s\TwenteBranding.Repository\Helpers\ItemHelper.cs:line 1810
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source, Func`2 predicate)
at TwenteBranding.Repository.Helpers.ItemHelper.GetJobCountByPartner(Int32 partnerId, PageService pageService, ItemService itemService) in D:\agent_2\_work\78\s\TwenteBranding.Repository\Helpers\ItemHelper.cs:line 1812
at TwenteBranding.Repository.Helpers.ItemHelper.GetTwenteBrandingItemForItem(String instanceType, Item item, String culture, PageService pageService, Boolean useParent) in D:\agent_2\_work\78\s\TwenteBranding.Repository\Helpers\ItemHelper.cs:line 784
at TwenteBranding.Repository.Helpers.ItemHelper.GetTwenteBrandingItemForSearchResultLoopItem(LoopItem baseLoopItem, String culture, PageService pageService, ItemService itemService, Boolean useParent) in D:\agent_2\_work\78\s\TwenteBranding.Repository\Helpers\ItemHelper.cs:line 254
at TwenteBranding.Repository.Helpers.ItemHelper.GetTwenteBrandingItemsFromQueryPublisherLoopItems(List`1 baseLoopItems, String currentPageId, String culture, String currentAreaId, Boolean allowWidgetInsertion, PageService pageService, ItemService itemService, Boolean useParent, QueryPublisherSortEnum sortType) in D:\agent_2\_work\78\s\TwenteBranding.Repository\Helpers\ItemHelper.cs:line 130
at CompiledRazorTemplates.Dynamic.RazorEngine_4c89c8bf78ab44dcb006544e0e1e3f56.Execute() in D:\inetpub\wwwroot\www.twente.com\Files\Templates\Designs\TwenteBranding\QueryPublisher\HashtagArticleQueryList.cshtml:line 22
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @using System.Globalization 2 @using Dynamicweb.Core 3 @using TwenteBranding.Repository.Helpers 4 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 5 @{ 6 var currentPage = Dynamicweb.Frontend.PageView.Current(); 7 if (currentPage != null && currentPage.Item != null && !string.IsNullOrWhiteSpace(currentPage.Item.Id)) 8 { 9 var articleResults = GetLoop("QueryResultItem"); 10 var hashtagId = currentPage.Item.Id; 11 12 if (articleResults.Any()) 13 { 14 var pageService = new Dynamicweb.Content.PageService(); 15 var itemService = new Dynamicweb.Content.ItemService(); 16 var culture = GetGlobalValue("Global:Area.LongLang"); 17 var currentAreaId = GetGlobalValue("Global:Area.ID"); 18 var currentPageId = GetGlobalValue("Global:Page.ID"); 19 20 var index = 1; 21 22 var twenteBrandingItems = ItemHelper.GetTwenteBrandingItemsFromQueryPublisherLoopItems(articleResults, currentPageId, culture, currentAreaId, false, pageService, itemService); 23 24 twenteBrandingItems = ItemHelper.FilterByHashtag(twenteBrandingItems, hashtagId, 0, false); 25 26 twenteBrandingItems = ItemHelper.EnrichList(twenteBrandingItems, currentPageId, culture, currentAreaId, pageService, itemService); 27 28 if (twenteBrandingItems != null && twenteBrandingItems.Any()) 29 { 30 foreach (var item in twenteBrandingItems) 31 { 32 var sort = item.Sort; 33 34 35 var title = item.Title; 36 var text = item.Text; 37 var earthIsCalling = item.EarthIsCalling; 38 var hashtag = item.MainHashtag.IsNotNullOrEmpty() ? item.MainHashtag : item.MainHashtagEnglish; 39 var detailsUrl = item.DetailsUrl; 40 var backgroundStyle = item.BackgroundStyle; 41 var backgroundImage = item.Image; 42 43 if (index == 1 && !string.IsNullOrWhiteSpace(item.BackgroundStyleFlat)) 44 { 45 backgroundStyle = item.BackgroundStyleFlat; 46 } 47 48 var goalName = item.GoalName; 49 var goalGradientCss = item.GoalGradientCss; 50 var goalIcon = item.GoalIcon; 51 var goalIconHeader = item.GoalIconHeader; 52 var goalIconOther = item.GoalIconOther; 53 var goalType = item.GoalType; 54 var goalClass = !string.IsNullOrWhiteSpace(detailsUrl) ? item.ClassName : string.Format("{0} no-link", item.ClassName); 55 var goalUrl = item.GoalUrl; 56 57 var fontColor = string.IsNullOrWhiteSpace(item.HeaderFontColor) ? "font-color--white" : item.HeaderFontColor; 58 59 switch (goalType) 60 { 61 case TwenteBranding.Models.Constants.StringConstants.ItemInstanceType.CallToActionArticle: 62 if (!string.IsNullOrWhiteSpace(item.ExternalUrl)) 63 { 64 detailsUrl = item.ExternalUrl; 65 } 66 67 <div class="item-container @goalClass item-clickable" style="order: @index"> 68 69 <div> 70 <div class="item" style="@backgroundStyle" data-src="@backgroundImage"> 71 72 @TwenteBranding.Repository.Helpers.ItemHelper.GetTileIconLink(goalIcon, goalUrl) 73 74 @*<h4 class="item-hashtag sub-header font-color--white">@hashtag</h4>*@ 75 76 <div class="item-content"> 77 <div class="item-content-text"> 78 <div class="call-to-action"> 79 <a class="item-link" href="@detailsUrl"> 80 @text 81 </a> 82 </div> 83 </div> 84 <div class="@goalGradientCss"></div> 85 </div> 86 </div> 87 </div> 88 89 </div> 90 break; 91 case TwenteBranding.Models.Constants.StringConstants.ItemInstanceType.EventArticle: 92 93 if (item.EventDateTo > DateTime.MinValue && item.EventDateTo < DateTime.Today.AddDays(1) || item.EventDateFrom > DateTime.MinValue && item.EventDateFrom < DateTime.Today.AddDays(1)) 94 { 95 break; 96 } 97 98 var eventOrganizer = item.EventOrganizer; 99 var eventCity = item.EventCity; 100 var eventLocation = item.EventLocation; 101 var eventPeriod = item.EventPeriod; 102 var eventPeriodDatesOnly = item.EventPeriodDatesOnly; 103 var eventPeriodTimesOnly = item.EventPeriodTimesOnly; 104 var eventInfo = FormatHelper.FormatEventInfo(eventCity, eventPeriodTimesOnly, eventOrganizer, Translate("EventOrganizer", "Organizer")); 105 106 <div class="item-container item-clickable item-eventarticle @goalClass" style="order: @index"> 107 <div> 108 <div class="item lazy" data-src="@backgroundImage" style="@backgroundStyle"> 109 110 @TwenteBranding.Repository.Helpers.ItemHelper.GetTileIconLink(goalIcon, goalUrl) 111 112 <h4 class="item-hashtag sub-header font-color--white">@hashtag</h4> 113 114 <div class="item-content"> 115 <div class="item-content-text"> 116 <h4 class="event-dateperiod font-color--white italic">@eventPeriodDatesOnly</h4> 117 </div> 118 <div class="@goalGradientCss item-gradient"></div> 119 </div> 120 121 </div> 122 123 <div class="event-details"> 124 <h2 class="event-title"> 125 <a class="item-link item-article" href="@detailsUrl"> 126 @title.ClipLength(50) 127 </a> 128 </h2> 129 @if (!string.IsNullOrWhiteSpace(eventInfo)) 130 { 131 <div class="event-info">@eventInfo</div> 132 } 133 </div> 134 </div> 135 136 </div> 137 break; 138 case TwenteBranding.Models.Constants.StringConstants.ItemInstanceType.JobOfferArticle: 139 140 var jobType = item.JobType; 141 var jobProduct = item.JobProduct; 142 var jobDiscipline = item.JobDiscipline; 143 var jobEducationalAttainment = item.JobEducationalAttainment; 144 var jobIntro = item.JobIntro; 145 var jobIntroInformationShort = item.JobIntroInformationShort; 146 var jobCompanyLogo = item.JobCompanyLogo; 147 jobCompanyLogo = $"/Admin/Public/GetImage.ashx?Image={jobCompanyLogo}&Format=webp&Width=200&Height=-1&Quality=100&Crop=0&t=2"; 148 var jobIsFeatured = true; 149 var jobCompanyIsPartner = item.JobCompanyIsPartner; 150 151 <div class="item-container item-clickable item-jobofferfeaturedarticle featured @goalClass" style="order: @index"> 152 <div class="item lazy" style="@backgroundStyle" data-src="@backgroundImage"> 153 154 @if (!string.IsNullOrWhiteSpace(jobCompanyLogo)) 155 { 156 <div class="joboffer-companylogo"><img alt="logo @title" class="lazy" data-src="@jobCompanyLogo" /></div> 157 } 158 else 159 { 160 @*<h4 class="item-hashtag sub-header font-color-joboffer">@hashtag</h4>*@ 161 <div class="joboffer-companylogo"></div> 162 163 } 164 165 <div class="item-content"> 166 <div class="item-content-text"> 167 168 <h2 class="joboffer-title font-color-joboffer"> 169 <a class="item-link" href="@detailsUrl"> 170 @title 171 </a> 172 </h2> 173 174 @{ 175 goalGradientCss = "no-gradient"; 176 var jobOfferInfo = TwenteBranding.Repository.Helpers.ItemHelper.CreateJobOfferInfoLine(culture, jobProduct, jobDiscipline, jobEducationalAttainment, jobIsFeatured); 177 178 <div class="joboffer-info font-color-joboffer"> 179 @jobOfferInfo 180 @jobIntroInformationShort 181 </div> 182 } 183 </div> 184 <div class="@goalGradientCss"></div> 185 </div> 186 </div> 187 </div> 188 break; 189 case TwenteBranding.Models.Constants.StringConstants.ItemInstanceType.VideoArticle: 190 191 var video = item.Video; 192 193 <div class="item-container item-videoarticle item-clickable @goalClass" style="order: @index"> 194 <div> 195 <div class="item lazy" style="@backgroundStyle" data-src="@backgroundImage"> 196 197 @TwenteBranding.Repository.Helpers.ItemHelper.GetTileIconLink(goalIcon, goalUrl) 198 199 <h4 class="item-hashtag sub-header font-color--white">@hashtag</h4> 200 201 <div class="video-icon icon--video icon-size--x4"></div> 202 203 <div class="item-content"> 204 <div class="item-content-text"> 205 <h2 class="font-color--white"> 206 <a class="item-link item-article" href="@detailsUrl">@title</a> 207 </h2> 208 </div> 209 <div class="@goalGradientCss"></div> 210 </div> 211 212 </div> 213 </div> 214 </div> 215 break; 216 case TwenteBranding.Models.Constants.StringConstants.ItemInstanceType.PartnerArticle: 217 218 var partnerLogo = item.PartnerLogo; 219 partnerLogo = $"/Admin/Public/GetImage.ashx?Image={partnerLogo}&Format=webp&Width=200&Height=-1&Quality=100&Crop=0&t=2"; 220 var partnerColor = item.PartnerColor; 221 var partnerIntro = item.PartnerIntro; 222 223 <div class="item-container item-clickable @goalClass" style="order: @index"> 224 <div class="item lazy" style="@backgroundStyle" data-src="@backgroundImage"> 225 <div class="item-content"> 226 <div class="item-content-text"> 227 228 <h2 class="partner-title @fontColor"><a class="item-link" href="@detailsUrl">@title</a></h2> 229 <h4 class="partner-hashtag @fontColor">@hashtag</h4> 230 <div class="partnerintro @fontColor">@partnerIntro</div> 231 @if (!string.IsNullOrWhiteSpace(partnerLogo)) 232 { 233 <div class="partnerlogo default"><img class="lazy" alt="logo @title" data-src="@partnerLogo" /></div> 234 } 235 236 </div> 237 @*<div class="@goalGradientCss"></div>*@ 238 </div> 239 <div class="partnerlogo partner"> 240 @if (!string.IsNullOrWhiteSpace(partnerLogo)) 241 { 242 <img alt="logo @title" class="lazy" data-src="@partnerLogo"/> 243 } 244 </div> 245 </div> 246 </div> 247 248 249 250 break; 251 case TwenteBranding.Models.Constants.StringConstants.ItemInstanceType.BaseArticle: 252 <div class="item-container item-basearticle item-clickable @goalClass" style="order: @index"> 253 <div> 254 <div class="item lazy" style="@backgroundStyle" data-src="@backgroundImage"> 255 @if (earthIsCalling) 256 { 257 @TwenteBranding.Repository.Helpers.ItemHelper.GetTileIconLink(goalIconHeader, goalUrl, earthIsCalling, goalIconOther) 258 <span class="item-hashtag sub-header font-color--white earth-is-calling">@hashtag</span> 259 } 260 else 261 { 262 @TwenteBranding.Repository.Helpers.ItemHelper.GetTileIconLink(goalIcon, goalUrl, earthIsCalling) 263 <h4 class="item-hashtag sub-header font-color--white">@hashtag</h4> 264 } 265 266 <div class="item-content"> 267 <div class="item-content-text"> 268 <h2 class="font-color--white @(earthIsCalling ? "earth-is-calling" : "")"> 269 <a class="item-link item-article" href="@detailsUrl">@title</a> 270 </h2> 271 </div> 272 <div class="@goalGradientCss"></div> 273 </div> 274 275 </div> 276 </div> 277 </div> 278 break; 279 default: // Page, GoalList, HashTag 280 <div class="item-container item-clickable @goalClass" style="order: @index"> 281 <div> 282 <div class="item" style="@backgroundStyle"> 283 <div class="item-content"> 284 <div class="item-content-text"> 285 <h2 class="font-color--white"><a class="item-link" href="@detailsUrl">@title</a></h2> 286 </div> 287 </div> 288 </div> 289 </div> 290 </div> 291 break; 292 } 293 294 index++; 295 } 296 297 @SnippetStart("Paging") 298 var prev = @GetString("DwPaging.PreviousPageLink"); 299 var curr = @GetInteger("DwPaging.CurrentPage"); 300 var total = @GetInteger("DwPaging.PageCount"); 301 var next = @GetString("DwPaging.NextPageLink"); 302 303 var allowPrev = curr == 1 ? "disabled" : ""; 304 var allowNext = curr == total ? "disabled" : ""; 305 306 <div class="paging"> 307 <a class="paging-prev button red button-small @allowPrev" href=@prev>@Translate("Paging_Prev", "Vorige")</a> 308 <span class="counter">@curr - @total</span> 309 <a class="paging-next button red button-small @allowNext" href=@next>@Translate("Paging_Next", "Volgende")</a> 310 </div> 311 @SnippetEnd("Paging") 312 } 313 314 } 315 } 316 } 317