Skip to content

Instantly share code, notes, and snippets.

@m3nt0r
Created September 21, 2010 05:58
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m3nt0r/589273 to your computer and use it in GitHub Desktop.
Save m3nt0r/589273 to your computer and use it in GitHub Desktop.
TwigView for CakePHP
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
{{ html.charset() }}
<title>{{ 'CakePHP: the rapid development php framework'|trans }}: {{ title_for_layout }}</title>
{{ html.meta('icon') }}
{{ html.css('cake.generic') }}
{{ scripts_for_layout }}
</head>
<body>
<div id="container">
<div id="header">
<h1>{{
html.link('CakePHP: the rapid development php framework'|trans, 'http://cakephp.org')
}}</h1>
</div>
<div id="content">
{{ session.flash() }}{{ session.flash('auth') }}
{{ content_for_layout }}
</div>
<div id="footer">
{{
html.image('cake.power.gif', [
'alt': 'Powered by CakePHP'|trans,
'url': 'http://cakephp.org'
])
}}
</div>
</div>
</body>
</html>
<h2>Just some Twig template</h2>
<p>{{ html.link('text', '#something') }}</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.</p>
{{ form.create('Account') }}
{{ form.input('email') }}
{{ form.input('username') }}
{{
form.input('password', [
'label':'Please enter your password'
])
}}
{{
form.input('option_test', [
'options':[
'red': 'Red Option',
'blue': 'Blue Option',
'green': 'Green Option'
]
])
}}
{{ form.end('Login') }}
/**
* Converted to plugin repo
*
* @see http://github.com/m3nt0r/cakephp-twig-view
*/
<h2>Elements with Twig</h2>
<p>Twig has it's very own "include" command. You can still use it, but it requires a full path relative to APP/views.</p>
<p>To make transition easier i've added a "element" command that looks in APP/views/elements and does not require the .tpl extension"</p>
<div id="something">
{{ element "my_element" }}
</div>
<p>The 'div#something' now has the contents of APP/views/elements/my_element.tpl</p>
<h2>Login</h2>
{{ form.create('Account') }}
{{
form.input('username', [
'label':'Your Username'|trans
])
}}
{{
form.input('password', [
'label':'Your Password'|trans
])
}}
{{
form.input('rememberMe', [
'label':'Remember for 2 weeks'|trans,
'type':'checkbox'
])
}}
{{ form.end('Log in now'|trans) }}
<p>Of course the trans block does work aswell. Just like the filter it pipes the contents to the CakePHP i18n functions "__()"</p>
{% trans %}
Hello {{ username }}!
This is a long translation block.
{% endtrans %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment