Error parsing template "Designs/Swift/_parsed/ProductDatasheet.parsed.cshtml"
Line 226: (225:36) - A space or line break was encountered after the "@" character. Only valid identifiers, keywords, comments, "(" and "{" are valid at the start of a code block and they must occur immediately following "@" with no space in between.
1 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
2 @using Dynamicweb.Ecommerce.Products
3 @using System
4
5 @{
6 var printMode = GetString("Global:Request.QueryString:print") == "1";
7 }
8
9 @{
10 // --- parser stubs (avoid page/media errors) ---
11 var page = Model;
12 var media = new object();
13
14 // --- helper to get querystring values (tries all common tag paths) ---
15 Func<string, string> QS = key =>
16 {
17 var paths = new[]
18 {
19 "Global:Request.QueryString:" + key,
20 "Global:Request.QueryString." + key,
21 "Global:QueryString:" + key,
22 "Global:QueryString." + key,
23 "Request.QueryString:" + key,
24 "Request:QueryString:" + key
25 };
26 foreach (var p in paths)
27 {
28 var val = GetString(p);
29 if (!string.IsNullOrWhiteSpace(val))
30 {
31 return val;
32 }
33 }
34 return null;
35 };
36
37 // --- collect params ---
38 string pid = null;
39 string lang = null;
40 string vid = null;
41
42 var idKeys = new [] { "productId","ProductID","ProductId","ID","Id","id","Number","number" };
43 var langKeys = new [] { "lang","Lang","LANG","Language","language" };
44 var varKeys = new [] { "variantId","VariantID","VariantId" };
45
46 foreach (var k in idKeys)
47 {
48 if (string.IsNullOrWhiteSpace(pid))
49 {
50 pid = QS(k);
51 }
52 }
53
54 foreach (var k in langKeys)
55 {
56 if (string.IsNullOrWhiteSpace(lang))
57 {
58 lang = QS(k);
59 }
60 }
61
62 foreach (var k in varKeys)
63 {
64 if (string.IsNullOrWhiteSpace(vid))
65 {
66 vid = QS(k);
67 }
68 }
69
70 if (string.IsNullOrWhiteSpace(lang))
71 {
72 lang = GetString("DwLanguageID");
73 }
74
75 if (string.IsNullOrWhiteSpace(pid))
76 {
77 @:Missing productId
78 return;
79 }
80
81 // --- Load product ---
82 var productService = new Dynamicweb.Ecommerce.Products.ProductService();
83 Product product = null;
84
85 try
86 {
87 product = productService.GetProductById(pid, lang, vid);
88 }
89 catch {}
90
91 if (product == null)
92 {
93 try
94 {
95 var svcType = productService.GetType();
96 var byNumber = svcType.GetMethod("GetProductByNumber", new Type[] { typeof(string), typeof(string) });
97 if (byNumber != null)
98 {
99 var obj = byNumber.Invoke(productService, new object[] { pid, lang });
100 product = obj as Product;
101 }
102 }
103 catch {}
104 }
105
106 if (product == null)
107 {
108 @:Product not found
109 return;
110 }
111
112 // --- fields ---
113 var name = product.Name;
114 var number = product.Number;
115 var ean = product.EAN ?? "";
116 var brand = product.Manufacturer != null ? product.Manufacturer.Name : "";
117 var shortDesc = product.ShortDescription ?? "";
118 var longDesc = product.LongDescription ?? "";
119
120 // --- image ---
121 var imageUrl = "";
122 if (!string.IsNullOrWhiteSpace(product.ImageLarge))
123 {
124 imageUrl = product.ImageLarge;
125 }
126 else if (!string.IsNullOrWhiteSpace(product.ImageMedium))
127 {
128 imageUrl = product.ImageMedium;
129 }
130 else if (!string.IsNullOrWhiteSpace(product.ImageSmall))
131 {
132 imageUrl = product.ImageSmall;
133 }
134
135 if (!string.IsNullOrWhiteSpace(imageUrl) && !imageUrl.StartsWith("/"))
136 {
137 imageUrl = "/" + imageUrl;
138 }
139 }
140
141 <!DOCTYPE html>
142 <html>
143 <head>
144 <meta charset="utf-8">
145 <title>@GetValue("Title")</title>
146 @GetValue("MetaTags")
147 @GetValue("CopyRightNotice")
148
149
150 <!-- PRINT-ONLY stylesheet (place the rules I gave you earlier into this file) -->
151 <link rel="stylesheet" href="/Files/Templates/Designs/%5BYourDesign%5D/css/print.css" media="print">
152
153 <!-- (Optional) Screen preview spacing only, has no effect on print -->
154 <style>
155 @media screen { body { margin:24px; font-family: Arial, Helvetica, sans-serif; color:#1f2937; } }
156 </style>
157
158 @GetValue("Stylesheets")
159 @GetValue("Javascripts")
160 </head>
161 <body>
162 <header style="display:flex;justify-content:space-between;align-items:flex-start;">
163 <div>
164 <h1>@name</h1>
165 <div class="muted">
166 @if (!string.IsNullOrWhiteSpace(number))
167 {
168 <text>Product No: @number</text>
169 }
170 @if (!string.IsNullOrWhiteSpace(ean))
171 {
172 <text> | EAN: @ean</text>
173 }
174 </div>
175 </div>
176 <div class="muted">Generated: @DateTime.UtcNow.ToString("yyyy-MM-dd")</div>
177 </header>
178
179 <div class="hr"></div>
180
181 <section class="grid">
182 <div class="figure">
183 @if (!string.IsNullOrWhiteSpace(imageUrl))
184 {
185 <img src="@imageUrl" alt="@name">
186 }
187 else
188 {
189 <div class="muted">No image</div>
190 }
191 </div>
192 <div>
193 @if (!string.IsNullOrWhiteSpace(shortDesc))
194 {
195 <p class="desc">@Raw(shortDesc)</p>
196 }
197 @if (!string.IsNullOrWhiteSpace(longDesc))
198 {
199 <h2>Description</h2>
200 <p class="desc">@Raw(longDesc)</p>
201 }
202 </div>
203 </section>
204
205 <h2>Specifications</h2>
206 <table>
207 <tbody>
208 @if (!string.IsNullOrWhiteSpace(brand))
209 {
210 <tr><th>Brand</th><td>@brand</td></tr>
211 }
212 @if (!string.IsNullOrWhiteSpace(lang))
213 {
214 <tr><th>Language</th><td>@lang</td></tr>
215 }
216 @* Add more rows as needed *@
217 </tbody>
218 </table>
219
220 <div class="footer">raaco • www.raaco.com</div>
221
222 <!-- Auto-fit to single A4 page on print -->
223 <script>
224 (function () {
225 function mmToPx(mm){ return (mm / 25.4) * 96; }
226 var pageHeightPx = 1122; // A4 @ ~96dpi
227 var topBottomMargins = mmToPx(12) * 2; // match @page margin
228 var available = pageHeightPx - topBottomMargins;
229
230 function fitToOnePage() {
231 var el = document.body;
232 // reset before measurement
233 el.style.transform = 'none';
234 el.style.width = 'auto';
235
236 var h = Math.max(
237 document.documentElement.scrollHeight,
238 document.body.scrollHeight
239 );
240
241 var scale = 1;
242 if (h > available) {
243 scale = Math.max(0.7, available / h); // don't shrink below 70%
244 el.style.transformOrigin = 'top left';
245 el.style.transform = 'scale(' + scale + ')';
246 // widen so scaled width still fills the printable width
247 el.style.width = (100 / scale) + '%';
248 }
249 }
250
251 window.addEventListener('load', function() {
252 setTimeout(function () {
253 fitToOnePage();
254 window.print();
255 }, 300);
256 });
257 })();
258 </script>
259
260
261 <footer class="print-footer">
262 <div class="footer-inner">
263 <div class="footer-text">
264 raaco A/S • Platanvej 19 • DK-4800 Nykøbing F. • Denmark • www.raaco.com
265 </div>
266 </div>
267 </footer>
268
269
270
271
272
273
274
275
276 </body>
277 </html>
278