Skip to content

Commit

Permalink
added custom sections
Browse files Browse the repository at this point in the history
  • Loading branch information
matthes committed Jul 25, 2018
1 parent 3b9e848 commit 7331124
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ Some Content
To use sections you must just set the callback:

```php
$textTemplate->setSectionCallback("sectionxy", function ($content, $params, $command, $context, $cmdParam) {
$textTemplate->addSection("sectionxy", function ($content, $params, $command, $context, $cmdParam) {
return "Content to replace section content with";
});
```
Expand Down
9 changes: 7 additions & 2 deletions src/TextTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,13 @@ function ($matches) use (&$nestingIndex, &$indexCounter, &$li, $blockTags) {

return $out;
} else if ($slash == "/") {
if ( ! isset ($nestingIndex[$tag]))
throw new TemplateParsingException("Line {$li}: Opening tag not found for closing tag: '{$matches[0]}'");
if ( ! isset ($nestingIndex[$tag])) {
if ( ! isset ($this->sections[$tag]) && ! in_array($tag, ["if", "for"]))
throw new TemplateParsingException("Line {$li}: No callback registred for section {{$tag}}{/{$tag}}");
throw new TemplateParsingException(
"Line {$li}: Opening tag not found for closing tag: '{$matches[0]}'"
);
}
if (count ($nestingIndex[$tag]) == 0)
throw new TemplateParsingException("Line {$li}: Nesting level does not match for closing tag: '{$matches[0]}'");
$curIndex = array_pop($nestingIndex[$tag]);
Expand Down

0 comments on commit 7331124

Please sign in to comment.