Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added if() filter

  • Loading branch information...
commit a1992edbec6fd4713cb077716eb040e2f8dd7678 1 parent a05ab5e
Arjen Brouwer authored
Showing with 43 additions and 0 deletions.
  1. +43 −0 lib/Twig/Extensions/Extension/If.php
43 lib/Twig/Extensions/Extension/If.php
View
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * This file is part of Twig.
+ *
+ * (c) 2009 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @author Arjen Brouwer <info@arjenbrouwer.nl>
+ * @package Twig
+ * @subpackage Twig-extensions
+ */
+class Twig_Extensions_Extension_If extends Twig_Extension
+{
+ /**
+ * Returns a list of filters.
+ *
+ * @return array
+ */
+ public function getFilters()
+ {
+ return array(
+ 'if' => new Twig_Filter_Function('twig_if_filter', array('needs_environment' => false))
+ );
+ }
+
+ /**
+ * Name of this extension
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return 'if';
+ }
+}
+
+function twig_if_filter($value, $condition)
+{
+ return ($condition) ? $value : null;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.