ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Continue and break control structure support in Antlers

Open godismyjudge95 opened this issue 1 year ago • 2 comments

Would be awesome if Antlers supported the continue and break control structures: https://www.php.net/manual/en/control-structures.break.php https://www.php.net/manual/en/control-structures.continue.php

Currently if you have a loop and you want to skip an item:

{{ posts }}
	{{ if id !== 1 }}
		{{ title }}
	{{ /if }}
{{ /posts }}

But if we had continue support (I think this would work? Not sure about the ?= syntax):

{{ posts }}
	{{ id === 1 ?= {continue} }}
	{{ title }}
{{ /posts }}

Or another scenario where this would be cleaner:

{{ bard_content }}
	{{ type === 'hr' ?= {break} }}
	<!-- Content as an excerpt (before the hr) -->
{{ /bard_content }}

godismyjudge95 avatar Feb 14 '24 04:02 godismyjudge95

Probably isn't helpful one bit but here is how Laravel Blade does it - https://github.com/laravel/framework/blob/10.x/src/Illuminate/View/Compilers/Concerns/CompilesLoops.php#L126-L152

godismyjudge95 avatar Feb 14 '24 04:02 godismyjudge95

This would be super useful. Some prior art: in Latte templates these are called continueIf and breakIf:

{foreach $rows as $row}
  {continueIf $row->date < $now}
  {breakIf $row->parent === null}
  ...
{/foreach}

daun avatar Feb 26 '24 14:02 daun