ソースを参照

Add smarty modifer in_array

markjcrane 2 年 前
コミット
7402e89a7f

+ 1 - 0
resources/classes/template.php

@@ -44,6 +44,7 @@
 					$this->object->setTemplateDir($this->template_dir);
 					$this->object->setCompileDir($this->cache_dir);
 					$this->object->setCacheDir($this->cache_dir);
+					$this->object->registerPlugin("modifier","in_array", "in_array");
 				}
 				if ($this->engine === 'raintpl') {
 					require_once "resources/templates/engine/raintpl/rain.tpl.class.php";

+ 23 - 0
resources/templates/engine/smarty/plugins/modifier.in_array.php

@@ -0,0 +1,23 @@
+<?php
+/**
+ * Smarty plugin
+ *
+ * @package    Smarty
+ * @subpackage PluginsModifier
+ */
+
+/**
+ * Smarty in_array modifier plugin
+ * Type:     modifier
+ * Name:     in_array
+ * Purpose:  Checks if a value exists in an array
+ *
+ * @param string  $needle
+ * @param array   $haystack
+ *
+ * @return boolean
+ */
+function smarty_modifier_in_array($needle, $haystack)
+{
+    return in_array($needle, $haystack);
+}