Skip to content

Commit

Permalink
added json_decode filter
Browse files Browse the repository at this point in the history
  • Loading branch information
marionnewlevant committed Jul 8, 2016
1 parent e169a72 commit efa214b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Making twig do things it really shouldn't. Twig is not intended to be a gene

- {% break %}, {% continue %}, and {% return %} tags
- `is numeric` test
- `json_decode` filter

## Installation

Expand Down Expand Up @@ -73,6 +74,10 @@ The test will return false for hexadecimal strings as this will be the default b
```

### Filters
- **json_decode**
Decode json string, returning php associative arrays. Uses the PHP [json_decode](http://php.net/manual/en/function.json-decode.php) function

## MN Twig Perversion Changelog

### 1.0.0 -- 2016.04.17
Expand All @@ -91,4 +96,8 @@ The test will return false for hexadecimal strings as this will be the default b

* Possibility of `{% return %}` with no value

### 1.1.0 -- 2016.07.08

* Added json_decode

Brought to you by [Marion Newlevant](http://marion.newlevant.com)
5 changes: 4 additions & 1 deletion mntwigperversion/MnTwigPerversionPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getReleaseFeedUrl()
*/
public function getVersion()
{
return '1.0.3';
return '1.1.0';
}

/**
Expand Down Expand Up @@ -122,10 +122,13 @@ public function hasCpSection()
public function addTwigExtension()
{
Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversionTwigExtension');

Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversion_Break_Node');
Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversion_Break_TokenParser');

Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversion_Continue_Node');
Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversion_Continue_TokenParser');

Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversion_Return_Node');
Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversion_Return_TokenParser');
// Craft::import('plugins.mntwigperversion.twigextensions.NumericTest');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,13 @@ public function getTests()
);
}

public function getFilters() {
return array(
'json_decode' => new \Twig_Filter_Method($this, 'jsonDecode'),
);
}

public function jsonDecode($str) {
return json_decode($str, true); // return assoc arrays (more twig-like)
}
}
8 changes: 8 additions & 0 deletions releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,13 @@
"[Added] {% return %} does not require a value to return",
"[Fixed] Renamed classes to prevent possible name conflicts"
]
},
{
"version": "1.1.0",
"downloadUrl": "https://github.com/marionnewlevant/craft-twig_perversion/archive/v1.1.0.zip",
"date": "2016-07-08T20:37:12.921Z",
"notes": [
"[Added] new filter json_decode"
]
}
]

1 comment on commit efa214b

@bossanova808
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this :)

Please sign in to comment.