I am trying to use Twig with CakePHP, so I installed this plugin:
https://github.com/predominant/TwigView
And in CakePHP's demo, we build a blog, and I can use this in a tpl file:
{% for post in posts %}
<tr>
<td>{{post.Post.id}}</td>
<td>{{post.Post.title}}</td>
<td>Edit | Delete</td>
<td>{{post.Post.created|date("F j, Y")}}</td>
</tr>
{% endfor %}
What I can't get to work, is converting this:
<?php
echo $this->Html->link(
'Add Post', array('controller' => 'posts', 'action' => 'add')
);
?>
I have tried all of these, and none of them work:
{{ html.link("Add Post", {"controller" : "posts", "action" : "add"}) }}
{{ _view.html.link("Add Post", {"controller" : "posts", "action" : "add"}) }}
{{ this.html.link("Add Post", {"controller" : "posts", "action" : "add"}) }}
I don't get any errors, it just gets replaced with nothing. Anyone know how I can fix this issue?
You have to explicitly declare the helpers in the controller to make it work:
See GitHub issue #14 and #13 where I got this from.
Maybe it just won't take an array as the argument or doesn't understand what controller or action is. Try:
Proper syntax for hyperlinks html helper is:
Is it escaping the output? If so, to get the full HTML, use RAW