mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
feat: allow liquid filters in for control flow statement
Some checks failed
tests / ci (push) Has been cancelled
Some checks failed
tests / ci (push) Has been cancelled
This commit is contained in:
parent
f777e850b1
commit
bcbb1be1da
2 changed files with 111 additions and 0 deletions
|
|
@ -230,6 +230,22 @@ class Plugin extends Model
|
|||
$template
|
||||
);
|
||||
|
||||
// Convert for loops with filters to use temporary variables
|
||||
// This handles: {% for item in collection | filter: "key", "value" %}
|
||||
// Converts to: {% assign temp_filtered = collection | filter: "key", "value" %}{% for item in temp_filtered %}
|
||||
$template = preg_replace_callback(
|
||||
'/{%\s*for\s+(\w+)\s+in\s+([^|]+)\s*\|\s*([^}]+)%}/',
|
||||
function ($matches) {
|
||||
$variableName = trim($matches[1]);
|
||||
$collection = trim($matches[2]);
|
||||
$filter = trim($matches[3]);
|
||||
$tempVarName = '_temp_' . uniqid();
|
||||
|
||||
return "{% assign {$tempVarName} = {$collection} | {$filter} %}{% for {$variableName} in {$tempVarName} %}";
|
||||
},
|
||||
$template
|
||||
);
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue