composer require ramsey/uuid
app/src/TemplateHelpers.php
<?php
namespace Heyday \TemplateHelpers ;
use SilverStripe \View \TemplateGlobalProvider ;
use SilverStripe \View \ArrayData ;
class TemplateHelpers implements TemplateGlobalProvider
{
public static function get_template_global_variables ()
{
return [
'ViewScope ' ,
];
}
public static function ViewScope (): ArrayData
{
return ArrayData ::create ([
'UniqueID ' => \Ramsey \Uuid \Uuid ::uuid4 ()->toString (),
]);
}
}
Components/Fields/Checkbox.ss
< % with $ViewScope %>
< div class ="field min-w-5 ">
< % if $Top.Value %>
< input type ="checkbox " name ="$Top.Name " id ="$UniqueID " value ="$Top.Value " class ="field-check " />
< % else %>
< input type ="hidden " name ="$Top.Name " value ="0 " />
< input type ="checkbox " name ="$Top.Name " id ="$UniqueID " value ="1 " class ="field-check " />
< % end_if %>
< label for ="$UniqueID " class ="block pl-7 leading-6 ">
$Top.Label
</ label >
</ div >
< % end_with %>
<% include Components/Fields/Checkbox Name='Something', Value='100', Label='Label value' %>