将网站从 HTML 转换为 Smarty
自从我学会了这一点以来,我有一系列 HTML 页面,我正在将它们转换为 Smarty 语法。该网站在设计方面相当古老,没有包含等 - 尽管我们的 .htaccess 允许我们将 PHP 视为 HTM 扩展。
我已将一些页面保存为 .tpl 页面,但是将其转换为完整模板的最佳方法是什么?
我一直在缓慢而乏味地将页面拆分为 .tpl 文件,尽管不确定这是否是正确的方法...该网站是一个联合创建的网站,可以追溯到 2006 年,最初是纯 HTML。
我使用模板引擎是因为这就是原始网站所有者想要的,而且我们都有能力使用模板引擎。
Smarty 的手册很有用;但我想知道如何执行 Smarty 分页脚本,其中数据像数据库结果一样分页(将一些数据移动到新数据库中,该数据库以前是包含在
http://i44.tinypic.com/5uh7nk.jpg
如果有其他解决方案(目前我们不太需要 CodeIgniter 等),我将不胜感激! ;)
I have a series of HTML pages which I am converting into Smarty syntax since I've learnt this. This site is a fairly old one in design terms, no include etc. - even though our .htaccess allows us to treat PHP as HTM extension.
I've saved a few as .tpl pages, but what's the best way to go about converting it into full-scale templating?
I've been slowly, but tediously, splitting pages into .tpl files, although not sure if that's the right way to do it... the site is a jointly-created one, dating back to 2006 originally as pure HTML.
I'm using a templating engine because that's what the original site-owner wanted, and we're both competent at using a templating engine.
The manual on Smarty was useful; but I'm wondering how to do a Smarty pagination script where the data is paginated like this for database results (moving some data into a new database that was formerly static data enclosed in < li > tags), rather than 1-10, 11-20 etc.:
http://i44.tinypic.com/5uh7nk.jpg
If there's another solution (for now we don't quite need CodeIgniter etc.) I'd appreciate the help! ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SmartyPaginate 插件可能会有所帮助。这是由一位最初的 Smarty 开发人员编写的。我不确定它是否与 Smarty 3 兼容(如果您使用的是 Smarty 3)。
另一种可能性是创建一个输出分页的模板,并接受一些参数来设置选项。
例如
,其中...
curpage
= 当前正在查看的页面,这将由 PHP 设置。perpage
= 每页显示多少个项目 - 这可能是由 php 设置的静态值,或者来自用户首选项numitems
= 总共有多少个项目 - 这是计算得出的通过 php/sql 并传递给模板link
= 将每个页面链接到的页面param
= 用于页码的参数,PHP 使用该参数来获取要查看的页面。即 items.php?p=1也就是说,您将使用 PHP 代码来检查 URL 中是否设置了页码,然后检查页码是否有效且在可接受的范围内。
您的实际页面内容只会循环遍历一系列项目,这些项目将是数据库的结果。根据获取的结果集,它将显示给定页面中的项目。
如果 SmartyPaginate 插件不起作用,您可能可以查看它以获取分页过程的帮助,并根据您的需求进行调整。
The SmartyPaginate plugin may help. This was written by one of the original Smarty developers. I'm not sure if it is compatible with Smarty 3 though, if that is what you're using.
The other possibility would be to create a template that outputs the pagination, and accepts some parameters to set the options.
e.g.
Where...
curpage
= the current page being viewed, this would be set by PHP.perpage
= how many items to show per page - this is probably a static value set by php, or from user preferencesnumitems
= how many total items there are - this is calculated by php/sql and passed to templatelink
= the page to link each page toparam
= the parameter to use for the page number, this is used by PHP to get the page to be viewed. i.e. items.php?p=1That said, you would use PHP code to check to see if a page number was set in the URL, and then check to see if the page number is valid and within the acceptable range.
Your actual page content would just loop over an array of items which would be the results from the database. Depending on what set of results was fetched, it will be showing items from the given page.
If the SmartyPaginate plugin won't work, you could probably look at it for help with the process of pagination and adapt it to your needs.