-
Notifications
You must be signed in to change notification settings - Fork 1
Basic concepts # Templates
The kitFramework is depending on a Model View Controller (MVC) pattern and uses the Twig template engine for the Views.
Assume your extension is named MyExtension, so the templates are expected in the path:
/kit2/extension/thirdparty/thirdParty/MyExtension/Template/default
Twig will access the templates with the Namespace, in this case:
@thirdParty/MyExtension
The subdirectory /default is also the name of the template = default.
The default template must exists. You (or the users of your extension) can add additional templates (directories), for example with another design or another functionality.
You can determine the template(s) in the configuration file framework.json:
"FRAMEWORK_TEMPLATES": [
"red",
"propangas24",
"mytemplate",
"default"
]
tells the kitFramework to search for the specified template first in the directory
/kit2/extension/thirdparty/thirdParty/MyExtension/Template/red
if the template does not exists, the kitFramework will look into
/kit2/extension/thirdparty/thirdParty/MyExtension/Template/propangas24
if the template does not exists, the kitFramework will step into
/kit2/extension/thirdparty/thirdParty/MyExtension/Template/mytemplate
and at least fall back into the /default directory.
If your extension support kitCommands the user can select a template with a parameter. Assume your kitCommand is named myextension then
~~ myextension template[mytemplate] ~~
will try to load the template mytemplate, otherwise the kitCommand will try to load the template red.
In your controller use the kitFramework Utilities function templateFile():
$template = $this->app['utils']->templateFile('@thirdParty/MyExtension/Template', 'template.twig');
to determine which template should be used for parsing the desired file. This function is expecting two parameters:
-
'@thirdParty/MyExtension/Template'- the Namespace for the Templates of your extension -
'template.twig'- the file name of the template. You can also specify a subdirectory.
Now let Twig render the template:
return $this->app['twig']->render($template, $variables);
$variables is an associative array containing all variables given from the controller to the template engine.
There are no restrictions in the usage of the template engine.
Please read the Twig Documentation to learn how to handle templates.
- If you spot a typo or want to contribute an article, a how-to or a tip, please feel free to edit the Wiki directly
- If you you have any question or suggestion, please contact the phpManufaktur Support Group
This Documentation is part of the KIT2 Project
© 2013 by phpManufaktur, kitFramework is published under MIT license.
- Silex Documentation
- Silex API
- Twig Template Engine
- Twig Short Reference
- Symfony Form Factory
- Doctrine DBAL
- Swift Mailer
- Requirements
- Installation
- .htaccess
- Configuration
- Constants
- Utilities
- Twig Extensions
- kitFramework API