我们使用模板引擎很久了
我从一个quicktemplate 然后使用smarttemplate
然后是smarty,后来越来越来模板引擎出来smarttemplate和smarty都是编译型模板就是把标签换成php代码但是我看手册可以支持类似模板标签
流程控制的替代语法
PHP 提供了一些流程控制的替代语法
,包括 if,while,for,foreach 和 switch。
替代语法的基本形式是把左花括号({)换成冒号(:),把右花括号(})
分别换成 endif;,endwhile;,endfor;,endforeach; 以及 endswitch;。
比如:<?php if ($a == 5): ?>
A is equal to 5
<?php endif; ?> <?php
if ($a == 5):
echo "a equals 5";
echo "...";
elseif ($a == 6):
echo "a equals 6";
echo "!!!";
else:
echo "a is neither 5 nor 6";
endif;
?> <?php foreach($list as $key=>$value):?>
<tr>
<td><?php echo $value['bookid'];?></td>
<td><?php echo $value['classname'];?></td>
<td><?php echo $value['typeid'];?></td>
<td><a href="<?php echo url_for("curd/show/id/".$value['bookid'])?>">显示</a></td>
<td><a href="<?php echo url_for("curd/edit/id/".$value['bookid'],true)?>">编辑</a></td>
<td><a href="<?php echo url_for("curd/delete/id/".$value['bookid'],true)?>">删除</a></td>
</tr>
<?php endforeach;?>
这些例子都是直接写代码有人会说模板引擎帮我们转换了,我们使用{} <%%> <{}>多方便。
我也感觉方便,但是我现在想我如果把页面做面内容块。每个地方都要
ob_start()
$out2 = ob_get_contents();
ob_end_clean();如果我做成一个控件样子如果没事我不使用 ob_get_contents取值
直接包含进来就可以吧了。直接按照php流程去执行
当然可以使用$obj->render();取得内容还有一个功能我在想 比如平时我们输出错误信息还得去调用 $page->error
能不能 当出错时候我才调用
比如 $error->view("403");这样输出错误
如果正常我这样输出
$content->view("content");这样子
我从一个quicktemplate 然后使用smarttemplate
然后是smarty,后来越来越来模板引擎出来smarttemplate和smarty都是编译型模板就是把标签换成php代码但是我看手册可以支持类似模板标签
流程控制的替代语法
PHP 提供了一些流程控制的替代语法
,包括 if,while,for,foreach 和 switch。
替代语法的基本形式是把左花括号({)换成冒号(:),把右花括号(})
分别换成 endif;,endwhile;,endfor;,endforeach; 以及 endswitch;。
比如:<?php if ($a == 5): ?>
A is equal to 5
<?php endif; ?> <?php
if ($a == 5):
echo "a equals 5";
echo "...";
elseif ($a == 6):
echo "a equals 6";
echo "!!!";
else:
echo "a is neither 5 nor 6";
endif;
?> <?php foreach($list as $key=>$value):?>
<tr>
<td><?php echo $value['bookid'];?></td>
<td><?php echo $value['classname'];?></td>
<td><?php echo $value['typeid'];?></td>
<td><a href="<?php echo url_for("curd/show/id/".$value['bookid'])?>">显示</a></td>
<td><a href="<?php echo url_for("curd/edit/id/".$value['bookid'],true)?>">编辑</a></td>
<td><a href="<?php echo url_for("curd/delete/id/".$value['bookid'],true)?>">删除</a></td>
</tr>
<?php endforeach;?>
这些例子都是直接写代码有人会说模板引擎帮我们转换了,我们使用{} <%%> <{}>多方便。
我也感觉方便,但是我现在想我如果把页面做面内容块。每个地方都要
ob_start()
$out2 = ob_get_contents();
ob_end_clean();如果我做成一个控件样子如果没事我不使用 ob_get_contents取值
直接包含进来就可以吧了。直接按照php流程去执行
当然可以使用$obj->render();取得内容还有一个功能我在想 比如平时我们输出错误信息还得去调用 $page->error
能不能 当出错时候我才调用
比如 $error->view("403");这样输出错误
如果正常我这样输出
$content->view("content");这样子
你也不用这么较劲也行的呵呵
我只是感觉query我看过手册挺不错的一个想法 但要是在弄个标签库就
更觉的好的缓存 我是因为我是从太频繁的操作数据库的话有点对数据库太苛刻
才建议你弄个标签库的呵呵 qq:541092062 我qq 我们可以探讨一下php方面的也许我很多地方有要问你的地方因为我也是个菜鸟呵呵
不是,我做了完了ORM类我想也做一个视图类。有时候做页耐时候输出错误不方便
或更换页面显示
不懂php的模板技术
没用过最好用下哦,用过也许知道什么是最合适的。
我意思是smarty还要存放缓存文件
还要加载smarty类
用他来写代码时,不人性化。
写个循环还要
LOOP 里面要判断一下键满足某指定规则 ,都要狗屎到查询手册半天,
是否值得推广有待商榷
反正我是不用的smarty 的作者们是典型的学院派,生生制造出一种“语言”,而不顾模板引擎的初衷
不该用的时候,就使用原生态的PHP.
it is too troubled to maintaining when the project is very great,
so, we need a template to separate the html from the script of the server.now, the reason is very clear why are you use the smarty in the project.ok, it is structured development before i said, what is the project of structured development, just like discuz,echop and wordpress, etc.but we must use the template to develop the web page ? , the answer is not sure,
because we use the frame to working my job. what is the mean doing something by the frame ? it mean that we use the OOP replace the structured development, the OOP frame is not need the template of the smarty that have the view layer to working instead of template.so, you could put the smarty away form your frame, but the other need him, just i talking about the structured development and some project that is dz,pw,wp... so so.just take it away, don`t make stupid yourself unless you want. - -!
至少目前还是有一部分受众群体,而且大部分框架也都支持集成smarty.我也用过好多模板,phplib fasttemplate,目前部分项目中还是一直用smarty.smarty的的确确是创立了一种"语言".
模板的推出,初衷就是解决分工,减少重复劳动,减少维护成本.
推出"语言"就是为了让专业的美工人员熟悉掌握,并处理一些简单的页面逻辑.
至于速度,他的编译功能可以很好的解决问题.
至于找个东西还要查询半天,只能说你用的不熟.
对于一个PHP都比较熟的人来说, smarty的语法,还是小case的,所以这不能成为理由.青蛙的英文拽的牛X, 大致明白了你的意思, 虽然有好多语法错误, 但我还是写不出来.
其实如果有人力物力和技术, 做适合自己的还是最佳选择.
smarty并不广泛, 除了ecshop这个大平台在应用, 其它的系统也没有用smarty, 比如phpcms dedecms discuz phpwind, 都与smarty无关。phpwind的模式值得学习一下。