Skip to content

Commit

Permalink
Merge pull request #8 from aoliverwd/develop
Browse files Browse the repository at this point in the history
Add clear method to clear export_string and return brace object
  • Loading branch information
aoliverwd authored May 2, 2021
2 parents 2de852d + f1d20fc commit e35df8a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ brace is a simple template language written in PHP. Brace uses a handlebar style
?>
```


### Instance variables

| Variable | Description | Default value |
Expand Down Expand Up @@ -372,4 +371,33 @@ Name is "John"
<!--
Comment block over multiple lines
-->
```

### Clearing cached process string

The ```clear``` method is useful when needing to processes multiple templates with differing data using the same brace instance.

By default brace does not clear a processed string at the end of executing a template/string parse.

```php

// Init brace
$brace = new brace\parser;
$brace->template_path = __DIR__.'/';

// Process first template
$brace->parse('example',[
'name' => [
'first' => 'John',
'last' => 'Doe'
]
]);

// Process second template using the same brace instance
$brace->clear()->parse('example_two',[
'name' => [
'first' => 'Dave',
'last' => 'Smith'
]
]);
```
10 changes: 9 additions & 1 deletion src/brace.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Brace
* Copyright (C) 2021 Alex Oliver
*
* @version: 1.0.5
* @version: 1.0.6
* @author: Alex Oliver
* @Repo: https://github.com/aoliverwd/brace
*/
Expand Down Expand Up @@ -101,6 +101,14 @@ public function return(): string{
return $this->export_string;
}

/**
* Clear export_string and return brace object
* @return object
*/
public function clear(): object{
$this->export_string = '';
return $this;
}

/**
* [reg_shortcode description]
Expand Down

0 comments on commit e35df8a

Please sign in to comment.