Class TemplateTask

Template Task can generate templated output Used in other Tasks. Acts like a simplified View class.

AppShell
Extended by TemplateTask
Package: Cake\Console\Command\Task
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Console/Command/Task/TemplateTask.php

Properties summary

  • array

    Paths to look for templates on. Contains a list of $theme => $path

  • $templateVars public
    array
    variables to add to template scope

Method Summary

  • _findTemplate() protected

    Find a template inside a directory inside a path. Will scan all other theme dirs if the template is not found in the first directory.

  • _findThemes() protected
    Find the paths to all the installed shell themes in the app.
  • generate() public
    Runs the template
  • Find the theme name for the current operation. If there is only one theme in $templatePaths it will be used. If there is a -theme param in the cli args, it will be used. If there is more than one installed theme user interaction will happen

  • initialize() public
    Initialize callback. Setup paths for the template task.
  • set() public
    Set variable values to the template scope

Method Detail

_findTemplate()source protected

_findTemplate( string $path , string $directory , string $filename )

Find a template inside a directory inside a path. Will scan all other theme dirs if the template is not found in the first directory.

Parameters

string $path
The initial path to look for the file on. If it is not found fallbacks will be used.
string $directory
Subdirectory to look for ie. 'views', 'objects'
string $filename
lower_case_underscored filename you want.

Returns

string
filename will exit program if template is not found.

_findThemes()source protected

_findThemes( )

Find the paths to all the installed shell themes in the app.

Bake themes are directories not named skel inside a Console/Templates path. They are listed in this order: app -> plugin -> default

Returns

array
Array of bake themes that are installed.

generate()source public

generate( string $directory , string $filename , array $vars null )

Runs the template

Parameters

string $directory
directory / type of thing you want
string $filename
template name
array $vars optional null
Additional vars to set to template scope.

Returns

string
contents of generated code template

getThemePath()source public

getThemePath( )

Find the theme name for the current operation. If there is only one theme in $templatePaths it will be used. If there is a -theme param in the cli args, it will be used. If there is more than one installed theme user interaction will happen

Returns

string
returns the path to the selected theme.

initialize()source public

initialize( )

Initialize callback. Setup paths for the template task.

set()source public

set( string|array $one , string|array $two null )

Set variable values to the template scope

Parameters

string|array $one
A string or an array of data.
string|array $two optional null

Value in case $one is a string (which then works as the key). Unused if $one is an associative array, otherwise serves as the values to $one's keys.

Properties detail

$templatePathssource

public array

Paths to look for templates on. Contains a list of $theme => $path

array()

$templateVarssource

public array

variables to add to template scope

array()

© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/2.9/class-TemplateTask.html