can I use a block inside an html tag?
- m.brecher
- Generous Backer | 905
@ando
Block inside html attribute isnt good way how dynamically add html attributes. The simplest way is use variable:
$this->template->myAttribute = 'data-my-attribute';
<div {$myAttribute}>
In latte is also something like n:attr, but direct rendering variable makes the code cleaner and more modern.
- 2bfree
- Member | 249
@mbrecher
Thanks much for this suggestion. For my case, where I combine template and “layout” overwrite I need to modify it a little bit.
{php $this->global->myAttribute = 'data-my-attribute="true"'}
<div {=$this->global->myAttribute ?? null|noescape}>
But it is also possible to do it more secure and flexible way:
{php $this->global->myAttribute['data-my-attribute'] = 'true'}
<div n:attr="$this->global->myAttribute">
Last edited by 2bfree (2025-09-15 19:38)