Created
March 23, 2011 13:49
-
-
Save caefer/883108 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace MyProject\MyBundle\Twig\Extension; | |
| class MyExtension extends \Twig_Extension | |
| { | |
| public function getFilters() | |
| { | |
| return array( | |
| 'toggle' => new \Twig_Filter_Method($this, 'doToggleFilter'), | |
| ); | |
| } | |
| public function doToggleFilter($parameters = array(), $key, $value) | |
| { | |
| if (isset($parameters[$key])) { | |
| $currentValues = explode(',', $parameters[$key]); | |
| if (($set = array_search($value, $currentValues))) { | |
| unset($currentValues[$set]); | |
| } else { | |
| $currentValues[] = $value; | |
| } | |
| $parameters[$key] = implode(',', $currentValues); | |
| } else { | |
| $parameters[$key] = $value; | |
| } | |
| return $parameters; | |
| } | |
| public function getName() | |
| { | |
| return 'my'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment