CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • AjaxView
  • Cell
  • Helper
  • HelperRegistry
  • JsonView
  • SerializedView
  • StringTemplate
  • View
  • ViewBlock
  • ViewBuilder
  • XmlView

Traits

  • CellTrait
  • StringTemplateTrait
  • ViewVarsTrait
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         3.0.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\View;
 16: 
 17: /**
 18:  * Adds string template functionality to any class by providing methods to
 19:  * load and parse string templates.
 20:  *
 21:  * This trait requires the implementing class to provide a `config()`
 22:  * method for reading/updating templates. An implementation of this method
 23:  * is provided by `Cake\Core\InstanceConfigTrait`
 24:  */
 25: trait StringTemplateTrait
 26: {
 27:     /**
 28:      * StringTemplate instance.
 29:      *
 30:      * @var \Cake\View\StringTemplate
 31:      */
 32:     protected $_templater;
 33: 
 34:     /**
 35:      * Sets templates to use.
 36:      *
 37:      * @param string[] $templates Templates to be added.
 38:      * @return $this
 39:      */
 40:     public function setTemplates(array $templates)
 41:     {
 42:         $this->templater()->add($templates);
 43: 
 44:         return $this;
 45:     }
 46: 
 47:     /**
 48:      * Gets templates to use or a specific template.
 49:      *
 50:      * @param string|null $template String for reading a specific template, null for all.
 51:      * @return string|array
 52:      */
 53:     public function getTemplates($template = null)
 54:     {
 55:         return $this->templater()->get($template);
 56:     }
 57: 
 58:     /**
 59:      * Gets/sets templates to use.
 60:      *
 61:      * @deprecated 3.4.0 Use setTemplates()/getTemplates() instead.
 62:      * @param string|array|null $templates null or string allow reading templates. An array
 63:      *   allows templates to be added.
 64:      * @return $this|string|array
 65:      */
 66:     public function templates($templates = null)
 67:     {
 68:         deprecationWarning(
 69:             'StringTemplateTrait::templates() is deprecated. ' .
 70:             'Use setTemplates()/getTemplates() instead.'
 71:         );
 72: 
 73:         if ($templates === null || is_string($templates)) {
 74:             return $this->templater()->get($templates);
 75:         }
 76: 
 77:         $this->templater()->add($templates);
 78: 
 79:         return $this;
 80:     }
 81: 
 82:     /**
 83:      * Formats a template string with $data
 84:      *
 85:      * @param string $name The template name.
 86:      * @param array $data The data to insert.
 87:      * @return string
 88:      */
 89:     public function formatTemplate($name, $data)
 90:     {
 91:         return $this->templater()->format($name, $data);
 92:     }
 93: 
 94:     /**
 95:      * Returns the templater instance.
 96:      *
 97:      * @return \Cake\View\StringTemplate
 98:      */
 99:     public function templater()
100:     {
101:         if ($this->_templater === null) {
102:             $class = $this->getConfig('templateClass') ?: 'Cake\View\StringTemplate';
103:             $this->_templater = new $class();
104: 
105:             $templates = $this->getConfig('templates');
106:             if ($templates) {
107:                 if (is_string($templates)) {
108:                     $this->_templater->add($this->_defaultConfig['templates']);
109:                     $this->_templater->load($templates);
110:                 } else {
111:                     $this->_templater->add($templates);
112:                 }
113:             }
114:         }
115: 
116:         return $this->_templater;
117:     }
118: }
119: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs