Dynamic include macro name

helvete
Member | 16
+
0
-

Hey,

is somehow possible to define block name dynamically in latte?

I am trying to achive something like this:

{include $coupon->getVoucherCampaignReward()->getCode() from './reward-block.latte', coupon: $coupon}

which doesn't work and results in parse error:

ParseError
syntax error, unexpected single-quoted string "./reward-block.latte", expecting "]"

But it works should I hardcode the value there like this:

{include electro from './reward-block.latte', coupon: $coupon}

I obviously don't like having it hardcoded as there is a lot of possible values there.

The template ./reward-block.latte contains many blocks.
Latte 2.11.2

Last edited by helvete (2022-08-29 10:41)

Marek Bartoš
Nette Blogger | 1273
+
+2
-

Expressions should work with {include block}

{include block $coupon->getVoucherCampaignReward()->getCode() from './reward-block.latte', coupon: $coupon}

I haven't tested it, so hopefully it will work :)

Last edited by Marek Bartoš (2022-08-25 20:11)

helvete
Member | 16
+
0
-

Hello

It indeed works! Thanks a lot.

It could be mentioned somewhere in the docs https://latte.nette.org/cs/tags#… though. Or perhaps I just missed it.

Cheers

Marek Bartoš
Nette Blogger | 1273
+
0
-

Could you create an issue? Unfortunately can't keep track of everything :D https://github.com/…/docs/issues?…

helvete
Member | 16
+
+1
-

Sure thing, why not.

Done: https://github.com/…s/issues/954

Last edited by helvete (2022-08-29 10:59)