Pylons/Pyramid Mako 风格模板可以在 CakePHP 中实现吗?
想知道是否可以在 CakePHP 中为我的视图进行模板化,就像在 Pylons/Pyramid 中使用 mako 模板化一样,通过定义一个元素(例如 comment_util
)并在其中放置一堆不同的元素?
本质上,您将有一个父元素,其中有一堆子元素,然后继承该名称空间,并在您在整个视图中调用它时传递您想要的任何内容(根据需要)。
Was wondering if it's possible in CakePHP to do templating for my views like you can in Pylons/Pyramid with mako templating by defining an element e.g. comment_util
and put a bunch of different elements within that?
Essentially you'd have one parent element, and within it, a bunch of child elements and then inherit that namespace and pass whatever you want when you call it throughout your views (as needed).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有使用 Pylons/Pyramid Mako,但我将回应您的解释:)
您可以调用您想要的所有元素,但建议您在动态内容(视图)的布局中使用内容进行布局,尽管您可以使用具有动态内容的元素。我在页面中有一个徽标元素,它动态地显示该页面代表的公司徽标。因为它在所有页面中,所以我将 $this->set 放在 appController 中。
您应该能够在元素内调用元素,因为 cake 所做的是元素的渲染,但我还没有测试它。所以理论上你想做的事情是可能的。只要确保始终设置您在内部使用的变量即可。
你用 $this->set 设置的内容也应该在你的元素中可用,至少这是我在 1.3 中的经验
希望这对你有帮助:)
I haven't used Pylons/Pyramid Mako, but im going to respond to what you explain :)
you may call all the elements you want, but you are advice to use content for layout in your layout for the dynamic content (the views), though you may use elements with dynamic contents. I have in a page a logo element that shows dinamicly the company logos the page represents. Since it was in all pages i put the $this->set inside the appController.
You should be able to call elements within elements since what cake does is a render of the element, i haven't test it though. So theorically is possible what you want to do. Just Make sure to always set the variables you are using inside.
What you set with $this->set should be available in your elements as well, at least that is what i have experience in 1.3
Hope this helps you :)