On Sun, 01 May 2016 03:50:51 GMT, Øivind Loe wrote:
Hi,
I am trying to generate classes based on a variables available to the diet template..
This works:
div - foreach(device; mDVC.mDevices) div.hauto-device .device-#{device.data.eco}-#{device.data.ecoDevType}
Due to the space, this will put ".device-..." between the <div></div>
tags instead of adding a class attribute.
This does not work (notice that I removed the space, adding two classes to the div tag.
div - foreach(device; mDVC.mDevices) div.hauto-device.device-#{device.data.eco}-#{device.data.ecoDevType}
The second gives the following error
Compiling diet template 'foo.dt'...
../../.dub/packages/vibe-d-0.7.28/vibe-d/source/vibe/templ/diet.d(1356,3): Error: "template foo.dt line 3: Expected identifier but got '{'.(../../.dub/packages/vibe-d-0.7.28/vibe-d/source/vibe/templ/diet.d:1241)"
../../.dub/packages/vibe-d-0.7.28/vibe-d/source/vibe/templ/diet.d(1241,13): called from here: this.assertp(start != idx, delegate string() => "Expected identifier but got '" ~ s[idx] ~ "'.", "../../.dub/paWhat am I doing wrong?
String interpolations are only allowed in node and attribute contents contents, so instead of using the shortcut class syntax, you need to specify an explicit attribute:
div
- foreach(device; mDVC.mDevices)
div.hauto-device(class="device-#{device.data.eco}-#{device.data.ecoDevType}")
The class attribute and the .hauto-device
shortcut will be automatically merged into a single class=""
attribute.