Carbon_Fields\Templater\Templater::add_template PHP Method

add_template() public static method

Register a new template.
public static add_template ( string $name, string $html )
$name string Template name
$html string Template content
    public static function add_template($name, $html)
    {
        // Check if the template is already added
        if (isset(self::$templates[$name])) {
            return false;
        }
        // Add the template to the stack
        self::$templates[$name] = $html;
    }

Usage Example

Beispiel #1
0
 /**
  * Adds the field/container template(s) to the templates stack.
  *
  * @param object $object field or container object
  **/
 public function add_templates($object)
 {
     $templates = $object->get_templates();
     if (!$templates) {
         return false;
     }
     foreach ($templates as $name => $callback) {
         ob_start();
         call_user_func($callback);
         $html = ob_get_clean();
         // Add the template to the stack
         Templater::add_template($name, $html);
     }
 }