Error executing template "Designs/Rapido/Paragraph/ParagraphContainer.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_3258673f523f41db8c8e16887f5a3621.Execute() in E:\Dynamicweb\Solutions\Kruuse\Files\Templates\Designs\Rapido\Paragraph\ParagraphContainer.cshtml:line 278
   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 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> 2 @using System.Collections.Generic 3 @using System 4 @using System.Text.RegularExpressions 5 6 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> 7 @using Dynamicweb.Frontend 8 9 @helper RenderContent(ItemViewModel item, bool isCarousel = false) 10 { 11 string cardClass = item.GetBoolean("ShowAsCard") ? "paragraph-card" : "grid__cell"; 12 cardClass = Pageview.Device.ToString() != "Tablet" ? cardClass : "grid__cell"; 13 14 string contentPosition = item.GetList("ContentPositions").SelectedValue; 15 16 switch (contentPosition) { 17 case "title-top": 18 <div class="@cardClass"> 19 @RenderHeading(item) 20 @RenderImage(item, isCarousel) 21 @RenderText(item) 22 @RenderModule(item) 23 </div> 24 @RenderButton(item) 25 break; 26 case "image-left": 27 <div class="grid"> 28 <div class="grid__col-3"> 29 @RenderImage(item, isCarousel) 30 </div> 31 <div class="grid__col-9"> 32 @RenderHeading(item) 33 @RenderText(item) 34 @RenderModule(item) 35 @RenderButton(item) 36 </div> 37 </div> 38 break; 39 case "image-right": 40 <div class="grid"> 41 <div class="grid__col-9"> 42 @RenderHeading(item) 43 @RenderText(item) 44 @RenderModule(item) 45 @RenderButton(item) 46 </div> 47 <div class="grid__col-3"> 48 @RenderImage(item, isCarousel) 49 </div> 50 </div> 51 break; 52 case "all-centered": 53 <div class="u-ta-center @cardClass"> 54 @RenderImage(item, isCarousel) 55 @RenderHeading(item) 56 @RenderText(item) 57 @RenderModule(item) 58 </div> 59 @RenderButton(item) 60 break; 61 case "middle-center": 62 case "middle-left": 63 @*Part of styles is placed in Paragraph.cshtml & ParagraphContainer.cshtml*@ 64 <div class="@(contentPosition == "middle-center" ? "grid--align-self-center" : "")"> 65 <div class="@cardClass"> 66 <div class="@(contentPosition == "middle-center" ? "u-ta-center" : "")"> 67 @RenderImage(item, isCarousel) 68 @RenderHeading(item) 69 @RenderText(item) 70 @RenderModule(item) 71 </div> 72 </div> 73 @RenderButton(item) 74 </div> 75 break; 76 //for "image-top" and "image-centered" 77 default: 78 <div class="@cardClass"> 79 @RenderImage(item, isCarousel) 80 @RenderHeading(item) 81 @RenderText(item) 82 @RenderModule(item) 83 </div> 84 @RenderButton(item) 85 break; 86 } 87 } 88 89 @helper RenderHeading(ItemViewModel item) 90 { 91 if (item.GetBoolean("ShowTitle") != false && !string.IsNullOrEmpty(item.GetString("Title"))) 92 { 93 string headerMargin = item.GetString("Text") != "" && item.GetString("Image") != "" ? "u-margin-bottom" : ""; 94 headerMargin = Model.GetModuleOutput() == "" ? headerMargin : "u-margin-bottom"; 95 string url = item.GetString("Link"); 96 97 if (!String.IsNullOrEmpty(url)) 98 { 99 <a href="@url"> 100 <h2 class="u-no-margin @headerMargin">@item.GetString("Title")</h2> 101 </a> 102 } 103 else 104 { 105 <h2 class="u-no-margin @headerMargin">@item.GetString("Title")</h2> 106 } 107 } 108 } 109 110 @helper RenderButton(ItemViewModel item) 111 { 112 string url = item.GetString("Link"); 113 string linkText = item.GetString("LinkText"); 114 string secondaryUrl = item.GetString("SecondaryLink"); 115 string secondaryLinkText = item.GetString("SecondaryLinkText"); 116 string footerCssClass = ""; 117 string cardFooterClass = item.GetBoolean("ShowAsCard") ? "paragraph-card-footer" : "grid__cell-footer"; 118 cardFooterClass = Pageview.Device.ToString() != "Tablet" ? cardFooterClass : ""; 119 string alingClass = ""; 120 121 if (item.GetList("ContentPositions").SelectedValue == "all-centered" || item.GetList("ContentPositions").SelectedValue == "middle-center") { 122 footerCssClass = "grid--justify-center"; 123 alingClass = "grid--justify-center"; 124 } 125 126 if ((!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(linkText)) || (!string.IsNullOrEmpty(secondaryUrl) && !string.IsNullOrEmpty(secondaryLinkText))) 127 { 128 <div class="grid__cell @footerCssClass @cardFooterClass"> 129 <div class="u-margin-top--lg u-margin-bottom @alingClass"> 130 131 @if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(linkText)) 132 { 133 string buttonStyle = !String.IsNullOrEmpty(item.GetList("ButtonDesign").SelectedValue) ? item.GetList("ButtonDesign").SelectedValue : "primary"; 134 135 if (url.Contains("http")) 136 { 137 <a href="@url" class="btn btn--@buttonStyle dw-mod" target="_blank">@linkText</a> 138 } 139 else if (url.StartsWith("/Files") || url.StartsWith("/Images")) 140 { 141 <a href="@url" class="btn btn--@buttonStyle dw-mod" download>@linkText</a> 142 } 143 else 144 { 145 <a href="@url" class="btn btn--@buttonStyle dw-mod">@linkText</a> 146 } 147 } 148 149 @if (!string.IsNullOrEmpty(secondaryUrl) && !string.IsNullOrEmpty(secondaryLinkText)) 150 { 151 string secondaryButtonStyle = !String.IsNullOrEmpty(item.GetList("SecondaryButtonDesign").SelectedValue) ? item.GetList("SecondaryButtonDesign").SelectedValue : "primary"; 152 153 if (secondaryUrl.Contains("http")) 154 { 155 <a href="@secondaryUrl" class="btn btn--@secondaryButtonStyle dw-mod" target="_blank">@secondaryLinkText</a> 156 } 157 else if (url.StartsWith("/Files") || url.StartsWith("/Images")) 158 { 159 <a href="@secondaryUrl" class="btn btn--@secondaryButtonStyle dw-mod" download>@secondaryLinkText</a> 160 } 161 else 162 { 163 <a href="@secondaryUrl" class="btn btn--@secondaryButtonStyle dw-mod">@secondaryLinkText</a> 164 } 165 } 166 </div> 167 </div> 168 } else { 169 <div class="grid__cell-footer @footerCssClass @cardFooterClass"></div> 170 } 171 } 172 173 @helper RenderText(ItemViewModel item) 174 { 175 if (!string.IsNullOrWhiteSpace(item.GetString("Text"))) 176 { 177 @item.GetString("Text") 178 } 179 } 180 181 @helper RenderModule(ItemViewModel item) 182 { 183 @Model.GetModuleOutput(); 184 } 185 186 @helper RenderImage(ItemViewModel item, bool isCarousel) 187 { 188 if (!string.IsNullOrEmpty(item.GetString("Image")) && item.GetList("ImageStyle").SelectedValue != "background") 189 { 190 string url = item.GetString("Link"); 191 192 <div class="u-margin-bottom"> 193 @if (!String.IsNullOrEmpty(url)) 194 { 195 <a href="@url"> 196 @RenderImageElement(item, isCarousel) 197 </a> 198 } 199 else 200 { 201 @RenderImageElement(item, isCarousel) 202 } 203 </div> 204 } 205 } 206 207 @helper RenderImageElement(ItemViewModel item, bool isCarousel) 208 { 209 string image = item.GetFile("Image") != null ? item.GetFile("Image").PathUrlEncoded : ""; 210 string imageFilterColor = item.GetList("ColorForTheFilter").SelectedValue != null ? item.GetList("ColorForTheFilter").SelectedValue : "none"; 211 string imageFilterPrimary = item.GetList("ImageFilterPrimary").SelectedValue != null ? item.GetList("ImageFilterPrimary").SelectedValue : "none"; 212 string imageFilterSecondary = item.GetList("ImageFilterSecondary").SelectedValue != null ? item.GetList("ImageFilterSecondary").SelectedValue : "none"; 213 string imageFilterBall = item.GetList("ImageStyle").SelectedValue == "ball" ? "image-filter--ball" : ""; 214 string altText = item.GetString("Title"); 215 string imgCssClass = ""; 216 string imgCrop = !string.IsNullOrEmpty(item.GetList("ImageCrop").SelectedValue) ? item.GetList("ImageCrop").SelectedValue : "5"; 217 bool fillCanvas = item.GetBoolean("FillCanvas") != null ? item.GetBoolean("FillCanvas") : true; 218 string fillCanvasString = fillCanvas == true ? "&amp;FillCanvas=true" : ""; 219 string imageBoxWidth = "480"; 220 int imageWidth = Int32.Parse(item.GetList("Width").SelectedValue) < 8 ? 620 : 1240; 221 int imageHeight = Int32.Parse(item.GetList("Width").SelectedValue) < 8 ? 496 : 950; 222 string placeHolderImage = "/Files/Images/placeholder.gif"; 223 224 if (imageFilterPrimary == "colorize") { 225 imageFilterPrimary = imageFilterColor; 226 } 227 228 if (item.GetList("ContentPositions").SelectedValue == "image-centered" || item.GetList("ContentPositions").SelectedValue == "all-centered" || item.GetList("ContentPositions").SelectedValue == "middle-center") 229 { 230 imgCssClass = "grid__cell-img--centered"; 231 } 232 233 <div class="image image-filter image-filter--@imageFilterPrimary @imageFilterBall dw-mod js-main-image-filter @(item.GetList("ContentPositions").SelectedValue == "middle-center" ? "u-middle" : "")"> 234 <div class="image-filter image-filter--@imageFilterSecondary @imageFilterBall dw-mod"> 235 @if (item.GetList("ImageStyle").SelectedValue == "ball") 236 { 237 imgCssClass += " grid__cell-img--ball"; 238 if (!isCarousel) 239 { 240 <img class="grid__cell-img @imgCssClass b-lazy" src="@placeHolderImage" data-src="/Admin/Public/GetImage.ashx?width=@imageBoxWidth&amp;height=@imageBoxWidth&amp;crop=@imgCrop&amp;Compression=75&amp;DoNotUpscale=true&amp;FillCanvas=true&amp;image=@image" alt="@altText"> 241 } 242 else 243 { 244 <img class="grid__cell-img @imgCssClass" src="/Admin/Public/GetImage.ashx?width=@imageBoxWidth&amp;height=@imageBoxWidth&amp;crop=@imgCrop&amp;Compression=75&amp;DoNotUpscale=true&amp;image=@image" alt="@altText"> 245 } 246 } 247 else 248 { 249 string retinaImage = "/Admin/Public/GetImage.ashx?width=" + imageWidth*2 + "&amp;height=" + imageHeight*2 + "&amp;crop=" + imgCrop + "&amp;Compression=75" + fillCanvasString + "&amp;DoNotUpscale=true&amp;image=" + image; 250 string largeImage = "/Admin/Public/GetImage.ashx?width=" + imageWidth + "&amp;height=" + imageHeight + "&amp;crop=" + imgCrop + "&amp;Compression=75" + fillCanvasString + "&amp;DoNotUpscale=true&amp;image=" + image; 251 string smallImage = "/Admin/Public/GetImage.ashx?width=" + imageWidth + "&amp;height=" + imageHeight + "&amp;crop=" + imgCrop + "&amp;Compression=75" + fillCanvasString+ "&amp;DoNotUpscale=true&amp;image=" + image; 252 253 if (!isCarousel) 254 { 255 <img class="@imgCssClass b-lazy" src="@placeHolderImage" data-src="@largeImage|@retinaImage" data-src-small="@smallImage" alt="@altText"> 256 } 257 else 258 { 259 <img class="@imgCssClass" src="@largeImage" alt="@altText"> 260 } 261 } 262 </div> 263 </div> 264 } 265 266 @{ 267 string fontColor = !string.IsNullOrEmpty(Model.Item.GetList("FontColor").SelectedValue) ? "u-" + Model.Item.GetList("FontColor").SelectedValue : ""; 268 string backgroundColor = !string.IsNullOrEmpty(Model.Item.GetList("BackgroundColor").SelectedValue) ? "u-" + Model.Item.GetList("BackgroundColor").SelectedValue + "--bg" : ""; 269 270 string paragraphContainerClasses = ""; 271 string containerClasses = ""; 272 string gridClasses = "grid "; 273 274 string spacingSize = Model.Item.GetList("Spacing") != null && Model.Item.GetList("Spacing").SelectedValue != "" ? Model.Item.GetList("Spacing").SelectedValue : "lg"; 275 string placeHolderImage = "/Files/Images/placeholder.gif"; 276 int columnCount = 0; 277 int paragraphCount = 0; 278 int totalParagraphs = Model.Item.GetItems("Paragraph").Count; 279 int totalSlides = 1; 280 281 switch (Model.Item.GetList("Width").SelectedValue) 282 { 283 case "center": 284 containerClasses += "center-container paragraph-container "; 285 paragraphContainerClasses += " " + fontColor + " " + backgroundColor; 286 break; 287 case "full": 288 containerClasses += fontColor + " " + backgroundColor + " "; 289 paragraphContainerClasses += "paragraph-container--full-width "; 290 break; 291 case "combi": 292 paragraphContainerClasses += "paragraph-container--full-width " + fontColor + " " + backgroundColor + " "; 293 containerClasses += "center-container paragraph-container "; 294 break; 295 default: 296 paragraphContainerClasses += "center-container "; 297 break; 298 } 299 300 if (spacingSize == "none") 301 { 302 containerClasses += "paragraph-container--spacing-none "; 303 } 304 305 //background 306 string containerBackgroundImage = ""; 307 string containerBackgroundImageSmall = ""; 308 string containerBackgroundImageFilterColor = Model.Item.GetList("ColorForTheFilter").SelectedValue != null ? Model.Item.GetList("ColorForTheFilter").SelectedValue : "none"; 309 string containerBackgroundImageFilterPrimary = Model.Item.GetList("ImageFilterPrimary").SelectedValue != null ? Model.Item.GetList("ImageFilterPrimary").SelectedValue : "none"; 310 string containerBackgroundImageFilterSecondary = Model.Item.GetList("ImageFilterSecondary").SelectedValue != null ? Model.Item.GetList("ImageFilterSecondary").SelectedValue : "none"; 311 312 if (containerBackgroundImageFilterPrimary == "colorize") 313 { 314 containerBackgroundImageFilterPrimary = containerBackgroundImageFilterColor; 315 } 316 317 if (Model.Item.GetFile("BackgroundImage") != null) 318 { 319 containerBackgroundImage = "/Admin/Public/GetImage.ashx?width=2500&amp;height=1100&amp;crop=0&amp;Compression=85&amp;DoNotUpscale=true&amp;image=" + Model.Item.GetFile("BackgroundImage").PathUrlEncoded; 320 containerBackgroundImageSmall = "/Admin/Public/GetImage.ashx?width=1000&amp;height=850&amp;crop=0&amp;&amp;FillCanvas=TrueCompression=85&amp;DoNotUpscale=true&amp;image=" + Model.Item.GetFile("BackgroundImage").PathUrlEncoded; 321 } 322 else if (string.IsNullOrEmpty(Model.Item.GetList("BackgroundColor").SelectedValue)) 323 { 324 backgroundColor = "u-color-light--bg"; 325 } 326 327 //separation line 328 bool haveSeparationLine = Model.Item.GetBoolean("SeperationLineAfter"); 329 if (haveSeparationLine && Model.Item.GetList("Width").SelectedValue != "center") 330 { 331 paragraphContainerClasses += "multiple-paragraphs-container--seperation-line-after "; 332 } 333 else if (haveSeparationLine) 334 { 335 containerClasses += "multiple-paragraphs-container--seperation-line-after "; 336 } 337 338 //height 339 if (!string.IsNullOrEmpty(Model.Item.GetList("Height").SelectedValue)) 340 { 341 gridClasses += "paragraph-container--height-" + Model.Item.GetList("Height").SelectedValue + " "; 342 } 343 344 //is visible for mobiles? 345 var hideForMobile = true; 346 foreach (var paragraph in Model.Item.GetItems("Paragraph")) 347 { 348 if (paragraph.GetList("WidthMobile").SelectedValue != "hide") 349 { 350 hideForMobile = false; 351 break; 352 } 353 } 354 if (Model.Item.GetItems("Paragraph").Count == 0) 355 { 356 hideForMobile = false; 357 } 358 359 if (hideForMobile) 360 { 361 gridClasses += "u-hidden-xs u-hidden-xxs "; 362 } 363 // 364 365 if (Model.Item.GetString("MakeParagraphsCenterAligned") != null && Model.Item.GetBoolean("MakeParagraphsCenterAligned")) 366 { 367 gridClasses += "grid--justify-center "; 368 } 369 370 string containerId = "Paragraph_" + Model.ID; 371 string carouselContainerClass = ""; 372 string carouselSlideClass = ""; 373 374 //Set as carousel 375 if (Model.Item.GetBoolean("EnableCarousel")) 376 { 377 containerClasses += "carousel js-carousel-container "; 378 containerClasses.Replace(" paragraph-container ", ""); 379 380 carouselContainerClass += "carousel__container dw-mod "; 381 382 carouselSlideClass += "carousel__slide dw-mod "; 383 384 containerId = "Carousel_" + Model.ID; 385 } 386 387 //getting video ID from youtube URL 388 string videoCode = Model.Item.GetString("VideoURL"); 389 Regex regex = new Regex(@".be\/(.[^?]*)"); 390 Match match = regex.Match(videoCode); 391 string videoId = ""; 392 if (match.Success) 393 { 394 videoId = match.Groups[1].Value; 395 } 396 else 397 { 398 regex = new Regex(@"v=([^&]+)"); 399 match = regex.Match(videoCode); 400 if (match.Success) 401 { 402 videoId = match.Groups[1].Value; 403 } 404 } 405 } 406 <div class="grid__col-md-12 grid__col--bleed"> 407 <section class="multiple-paragraphs-container @paragraphContainerClasses multiple-paragraphs-container--spacing-@spacingSize dw-mod"> 408 <div class="background-image image-filter image-filter--@containerBackgroundImageFilterPrimary dw-mod"> 409 <div class="background-image__wrapper image-filter image-filter--@containerBackgroundImageFilterSecondary dw-mod"> 410 <img class="background-image__cover dw-mod b-lazy" src="@placeHolderImage" data-src="@containerBackgroundImage" data-src-small="@containerBackgroundImageSmall" alt=""> 411 @if (!string.IsNullOrEmpty(videoId)) 412 { 413 <div class="video-background"> 414 <div class="video-background__container"> 415 <div class="js-youtube-video" data-video="@videoId" id="ytPlayer@(Model.ID)"></div> 416 </div> 417 </div> 418 } 419 </div> 420 </div> 421 <div class="@containerClasses dw-mod" id="@containerId"> 422 <div class="@carouselContainerClass"> 423 <div class="@carouselSlideClass"> 424 <div class="@gridClasses dw-mod"> 425 @foreach (var paragraph in Model.Item.GetItems("Paragraph")) 426 { 427 int columnWidth = Pageview.Device.ToString() != "Mobile" ? Int32.Parse(paragraph.GetList("Width").SelectedValue) : 12; 428 429 if (columnCount < 12) 430 { 431 columnCount += columnWidth; 432 } 433 else 434 { 435 columnCount = columnWidth; 436 } 437 438 string columnCssClasses = "grid__col-sm-" + columnWidth + " "; 439 if (paragraph.GetList("WidthMobile").SelectedValue != "hide") 440 { 441 columnCssClasses += "grid__col-xs-" + paragraph.GetList("WidthMobile").SelectedValue + " "; 442 } 443 else 444 { 445 columnCssClasses += "u-hidden-xs u-hidden-xxs "; 446 } 447 string backgroundImage = ""; 448 string backgroundImageSmall = ""; 449 string imageStyle = paragraph.GetList("ImageStyle").SelectedValue; 450 string backgroundImageFilterColor = paragraph.GetList("ColorForTheFilter").SelectedValue != null ? paragraph.GetList("ColorForTheFilter").SelectedValue : "none"; 451 string backgroundImageFilterPrimary = paragraph.GetList("ImageFilterPrimary").SelectedValue != null ? paragraph.GetList("ImageFilterPrimary").SelectedValue : "none"; 452 string backgroundImageFilterSecondary = paragraph.GetList("ImageFilterSecondary").SelectedValue != null ? paragraph.GetList("ImageFilterSecondary").SelectedValue : "none"; 453 454 if (imageStyle == "background" && paragraph.GetFile("Image") != null) 455 { 456 string cropMode = paragraph.GetList("ImageCrop").SelectedValue != null ? paragraph.GetList("ImageCrop").SelectedValue : "0"; 457 backgroundImage = "/Admin/Public/GetImage.ashx?width=2500&amp;height=1100&amp;crop=" + cropMode + "&amp;Compression=85&amp;DoNotUpscale=true&amp;image=" + paragraph.GetFile("Image").PathUrlEncoded; 458 backgroundImageSmall = "/Admin/Public/GetImage.ashx?width=1000&amp;height=850&amp;crop=" + cropMode + "&amp;Compression=85&amp;DoNotUpscale=true&amp;image=" + paragraph.GetFile("Image").PathUrlEncoded; 459 } 460 461 if (backgroundImageFilterPrimary == "colorize") 462 { 463 backgroundImageFilterPrimary = backgroundImageFilterColor; 464 } 465 466 string paragraphContainerPadding = paragraph.GetBoolean("HidePadding") ? "paragraph-container--no-padding" : ""; 467 string contentPosition = paragraph.GetList("ContentPositions").SelectedValue; 468 string contentPositionClasses = contentPosition == "middle-center" || contentPosition == "middle-left" ? "grid--justify-center " : ""; 469 470 <div class="@columnCssClasses paragraph-container @paragraphContainerPadding dw-mod @contentPositionClasses"> 471 @if (imageStyle == "background" && paragraph.GetFile("Image") != null) 472 { 473 <div class="background-image image-filter image-filter--@backgroundImageFilterPrimary dw-mod"> 474 <div class="background-image__wrapper image-filter image-filter--@backgroundImageFilterSecondary dw-mod"> 475 <img class="background-image__cover dw-mod b-lazy" src="@placeHolderImage" data-src="@backgroundImage" data-src-small="@backgroundImageSmall" alt=""> 476 </div> 477 </div> 478 } 479 480 @RenderContent(paragraph, Model.Item.GetBoolean("EnableCarousel")) 481 </div> 482 483 paragraphCount++; 484 if (paragraphCount != totalParagraphs) 485 { 486 string breakMarkup = string.Empty; 487 if (columnCount == 12) 488 { 489 breakMarkup = "</div></div><div class=\"" + carouselSlideClass + "\"><div class=\"" + gridClasses + "\">"; 490 totalSlides++; 491 } 492 @breakMarkup 493 } 494 } 495 </div> 496 </div> 497 </div> 498 499 @if (Model.Item.GetBoolean("EnableCarousel") && totalSlides > 1) 500 { 501 <div class="js-carousel-data" data-carousel-slide-time="@Model.Item.GetString("SlideTime")" data-slides-in-view="1"> 502 <div class="carousel-prev-btn dw-mod" onclick="Carousel.GetPreviousSlide('@containerId', true)"></div> 503 <div class="carousel-next-btn dw-mod" onclick="Carousel.GetNextSlide('@containerId', true)"></div> 504 </div> 505 } 506 </div> 507 </section> 508 </div>