1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
2 @using System.IO
3
4 @{
5 string layout = Model.Item.GetRawValueString("Layout", "icon-top");
6 string contentPadding = Model.Item.GetRawValueString("ContentPadding", "");
7 contentPadding = contentPadding == "none" ? "" : contentPadding;
8 contentPadding = contentPadding == "small" ? "p-3 p-md-3" : contentPadding;
9 contentPadding = contentPadding == "large" ? "p-5 p-md-5" : contentPadding;
10 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : "";
11 }
12
13 <div class="h-100 @(contentPadding)@(theme)
[email protected]()">
14 @switch (layout)
15 {
16 case "icon-top":
17 if (!string.IsNullOrEmpty(Model.Item.GetString("Link")))
18 {
19 @:<a href="@Model.Item.GetString("Link")" class="text-decoration-none d-block h-100">
20 }
21
22 <div class="d-flex flex-column gap-3 text-center mb-0-last-child">
23 <div>
24 @RenderIconAndImage()
25 </div>
26
27 @if (
28 !string.IsNullOrEmpty(Model.Item.GetString("Title")) &&
29 !Model.Item.GetBoolean("HideTitle") ||
30 !string.IsNullOrEmpty(Model.Item.GetString("Text"))
31 )
32 {
33 <div class="mb-0-last-child">
34 @RenderTitle()
35 @RenderBody()
36 </div>
37 }
38
39 </div>
40
41 if (!string.IsNullOrEmpty(Model.Item.GetString("Link")))
42 {
43 @:</a>
44 }
45 break;
46 case "icon-left":
47 if (!string.IsNullOrEmpty(Model.Item.GetString("Link")))
48 {
49 @:<a href="@Model.Item.GetString("Link")" class="text-decoration-none d-block h-100">
50 }
51
52 <div class="d-flex flex-row align-items-stretch gap-3 h-100 text-start">
53 <div class="flex-grow-0">
54 @RenderIconAndImage()
55 </div>
56
57 @if (
58 !string.IsNullOrEmpty(Model.Item.GetString("Title")) &&
59 !Model.Item.GetBoolean("HideTitle") ||
60 !string.IsNullOrEmpty(Model.Item.GetString("Text"))
61 )
62 {
63 <div class="d-flex flex-column flex-grow-1 gap-3">
64 @RenderTitle()
65 @RenderBody()
66 </div>
67 }
68
69 </div>
70
71 if (!string.IsNullOrEmpty(Model.Item.GetString("Link")))
72 {
73 @:</a>
74 }
75 break;
76 case "icon-right":
77 if (!string.IsNullOrEmpty(Model.Item.GetString("Link")))
78 {
79 @:<a href="@Model.Item.GetString("Link")" class="text-decoration-none d-block h-100">
80 }
81
82 <div class="d-flex flex-row align-items-stretch gap-3 h-100 text-end">
83 <div class="d-flex flex-column flex-grow-1 gap-3">
84 @RenderTitle()
85 @RenderBody()
86 </div>
87
88 <div class="flex-grow-0">
89 @RenderIconAndImage()
90 </div>
91 </div>
92 if (!string.IsNullOrEmpty(Model.Item.GetString("Link")))
93 {
94 @:</a>
95 }
96 break;
97 }
98 </div>
99
100 @helper RenderIconAndImage()
101 {
102 string iconSize = Model.Item.GetRawValueString("IconSize", "2");
103 string imageSrc = !string.IsNullOrEmpty(Model.Item.GetString("Image")) ? Model.Item.GetFile("Image").Path : "";
104
105 if (!string.IsNullOrEmpty(Model.Item.GetString("Image")))
106 {
107 @RenderIcon(imageSrc, iconSize)
108 }
109 else
110 {
111 string imagePath = Model.Item.GetRawValueString("Icon", "");
112
113 if (!imagePath.ToLower().Contains("none") && imagePath != "")
114 {
115 @RenderIcon(imagePath, iconSize)
116 }
117 }
118 }
119
120 @helper RenderIcon(string imagePath, string iconSize)
121 {
122 if (Path.GetExtension(imagePath).ToLower() == ".svg")
123 {
124 <div class="icon-auto" style="height: @(iconSize)px; width: @(iconSize)px;">
125 @ReadFile(imagePath)
126 </div>
127 }
128 else
129 {
130 int iconSizeX3 = (Convert.ToInt32(iconSize) * 3);
131
132 imagePath = "/Admin/Public/GetImage.ashx?image=" + imagePath + "&height=" + iconSizeX3 + "&width=" + iconSizeX3 + "&Crop=0&Format=WebP&Quality=100";
133
134 <img loading="lazy" src="@imagePath" title="@Model.Item.GetString("Title")" style="height: @(iconSize)px; width: @(iconSize)px;">
135 }
136 }
137
138 @helper RenderTitle()
139 {
140 string titleFontSize = Model.Item.GetRawValueString("TitleFontSize", "h4");
141
142 if (!string.IsNullOrEmpty(Model.Item.GetString("Title")) && !Model.Item.GetBoolean("HideTitle"))
143 {
144 <h2 class="@titleFontSize m-0">@Model.Item.GetString("Title")</h2>
145 }
146 }
147
148 @helper RenderBody()
149 {
150 if (!string.IsNullOrEmpty(Model.Item.GetString("Text")))
151 {
152 <p class="m-0">@Model.Item.GetString("Text")</p>
153 }
154 }
155