使用纯文本加载视图代码符号 [英] Load view codeigniter with plain text
本文介绍了使用纯文本加载视图代码符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用codeigniter为我的网站,我想知道如果我可以加载视图中的视图,而不使用PHP。因此,像模板解析器一样,可以运行此代码:
I am using codeigniter for my website and I was wondering if I could load a view in a view without using PHP. So like a Template Parser, is it possible to run this code:
<div>
<?php $this->load->view('widget'); ?>
</div>
使用纯文本格式:
<div>
{loadview:widget}
</div>
Tnx
推荐答案
对不起,但Codeigniter没有内置的这样做。您必须查看使用第三方模板解析器或书写
一些建议:
- Twig: http://twig.sensiolabs.org/ (推荐)
- Smarty: http://www.smarty.net/
- Dwoo: http://dwoo.org/
- 小胡子: http://mustache.github.com/ (不完整,但语言独立)
- Twig: http://twig.sensiolabs.org/ (recommend)
- Smarty: http://www.smarty.net/
- Dwoo: http://dwoo.org/
- Mustache: http://mustache.github.com/ (not full featured, but language indepenent)
使用 CI的原生模板解析器,您可以将包含内容的变量:
With CI's native template parser, you can assign a variable that contains the content:
$data['widget'] = $this->load->view('widget', NULL, TRUE);
$this->load->view('my_view', $data);
第三个参数为 TRUE
所以你可以使用它在一个变量,而不打印。然后在您的视图中:
The third param as TRUE
buffers the output so you can use it in a variable without it printing. Then in your view:
<div>
{{widget}}
</div>
..但目前,CI的解析器功能非常有限。我会和Twig或Smarty一起去。
..but currently, CI's parser has very limited capabilities. I'd go with Twig or Smarty.
这篇关于使用纯文本加载视图代码符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文