代码预测器“模板”系统 [英] CodeIgniter "Template" system

查看:79
本文介绍了代码预测器“模板”系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我开始一个新项目时,我发现自己重构和重新思考我自己制作的模板库。我使用了dom操作的一些影响,但不想生成太多的函数,所以它仍然加载快。

Whenever I start a new project I find myself remaking and rethinking my self made template library. I use some influences from dom manipulation, but don't want to make too much functions so that it still loads fast.

这是我当前的模板系统的样子:

This is how my current template system looks like:

这是一个布局文件:

<body>
<div id="content">
    <block:content>This is a default text</block:content>
</div>
<div id="sidebar">
    <widget:advertisement type="wide" />
    <block:sidebar this_param="is_passed_on" />
</div>
</body>

正如你所看到的,我做了2种额外标签,模板。我加载这个布局像这样:

As you can see I made 2 sort of "extra" tags that will be replaced when eventually publishing the template. I load this layout like this:

$this->template->load("layout");

然后我可以像这样操作块标签:

I then can manipulate the block tags like this:

$this->template->content = "I'm overwriting the default text";
$this->template->content->prepend("I forgot something");

$this->template->sidebar->view("viewfile_1", array(/*data*/));
$this->template->sidebar->view("viewfile_2", array(/*data*/));



我可以手动设置文本,我可以加载多个视图到1块,我可以使用几个dom ...

I can set text manually, I can load multiple views into 1 block, I can use a few dom-like manipulating functions like prepend, append, ...

我甚至可以使用更多布局选项扩展模板:

I can even extend the template with more layout options like:

$this->template->content->extend("2columns");

此布局文件可能如下所示:

This layout file might look like:

<div><block:left/></div>
<div><block:right/></div>

因此,代替内容块,我现在有一个额外的左右块来放置内容。

So that instead of the content block I now have an extra left and right block to put content in.

我还创建了一个小部件标记,用于加载特定的小部件类(在这种情况下是/ widgets / ads)。标签中添加的可选参数与直接传递的数据数组一起传递到视图文件和/或窗口小部件显示功能。

I have also created a widget tag that loads the specific widget class (/widgets/advertisement in this case). The optional parameters added in the tags are passed on to the views files and/or widget display function together with the direct passed data array.

总之,这是我的系统现在工作。我还没有真正发现其他系统这样从灵感。

In short, this is how my system now works. I haven't really found other systems like this to get inspiration from. Could you guys give me advice on anything so I can put together one decent system that I can keep using?

推荐答案

我的方法是,你可以给我建议一个正常的系统, :

My approach is:


  • 在布局/文件夹上为每个页面类型创建主要布局

  • 在公共/文件夹中创建通用位接口
  • http://getsparks.org/packages/template/versions/HEAD/showrel =nofollow> Phil Sturgeon的模板库(或Spark!)来处理视图。
  • 在每个控制器上,我加载渲染所需的所有数据在$ this-> data,我将该对象传递给视图

  • Create main layouts for each page type on a layouts/ folder (think Wordpress layouts for home, archive, single post, single page)
  • Create common bits of interface in a common/ folder (think header, footer, sidebar, widget_XX, widget_YY)
  • Use Phil Sturgeon's Template Library (or Spark!) to handle the views.
  • On each controller I load all the data needed for rendering in $this->data and I pass that object to the view

希望这有帮助!祝你好运。

Hope this helps! Good luck.

这篇关于代码预测器“模板”系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆