protected function resolveConditionals(string $template, array $variables): string
    {
        do {
            $template = preg_replace_callback(
                '/\{%\s*if(?<index>-[\d]+-[\d]+-)\s+(?<not>not\s+)?' . self::REGEX_VARIABLE . '\s*%\}' .
                    '(?<body>.+)' .
                '\{%\s*endif\k<index>\s*%\}/si',
                function (array $matches) use ($variables): string {
                    $conditionalBody = preg_split("/{%\s*else{$matches['index']}\s*%\}/si", $matches['body']);
                    $ifCondition = $this->getValue($matches, $variables);

                    if (strlen($matches['not']) xor $ifCondition) {
                        return $conditionalBody[0];
                    }

                    return $conditionalBody[1] ?? '';
                },
                $template,
                -1,
                $count
            );
        } while ($count > 0);

        return $template;
    }
protected function resolveConditionals(string $template, array $variables): string
    {
        do {
            $template = preg_replace_callback(
                '/\{%\s*if(?<index>-[\d]+-[\d]+-)\s+(?<not>not\s+)?' . self::REGEX_VARIABLE . '\s*%\}' .
                    '(?<body>.+)' .
                '\{%\s*endif\k<index>\s*%\}/si',
                function (array $matches) use ($variables): string {
                    $conditionalBody = preg_split("/{%\s*else{$matches['index']}\s*%\}/si", $matches['body']);
                    $ifCondition = $this->getValue($matches, $variables);

                    if (strlen($matches['not']) xor $ifCondition) {
                        return $conditionalBody[0];
                    }

                    return $conditionalBody[1] ?? '';
                },
                $template,
                -1,
                $count
            );
        } while ($count > 0);

        return $template;
    }
protected function resolveConditionals ( string $ template , array $ variables ) : string { do { $ template = preg_replace_callback ( '/\{%\s*if(?<index>-[\d]+-[\d]+-)\s+(?<not>not\s+)?' . self :: REGEX_VARIABLE . '\s*%\}' . '(?<body>.+)' . '\{%\s*endif\k<index>\s*%\}/si' , function ( array $ matches ) use ( $ variables ) : string { $ conditionalBody = preg_split ( "/{%\s*else{$matches['index']}\s*%\}/si" , $ matches [ 'body' ] ) ; $ ifCondition = $ this -> getValue ( $ matches , $ variables ) ; if ( strlen ( $ matches [ 'not' ] ) xor $ ifCondition ) { return $ conditionalBody [ 0 ] ; } return $ conditionalBody [ 1 ] ?? '' ; } , $ template , - 1 , $ count ) ; } while ( $ count > 0 ) ; return $ template ; }
Resolve conditionals in a given template section

@param string $template  The template section
@param array  $variables The current variable scope

@return string
@throws UndefinedSymbolException
@throws SyntaxErrorException
Resolve conditionals in a given template section