【问题标题】:Inserting a variable argument into a Silverstripe template's function?将变量参数插入到 Silverstripe 模板的函数中?
【发布时间】:2012-02-16 15:54:36
【问题描述】:

我正在使用来自 balbus design 的 pagination example。在.ss模板中,有一行代码:

<% control ProductList.PaginationSummary(5) %>

是否可以使用变量而不是硬编码值5?例如:

<% control ProductList.PaginationSummary(PSSize) %>

变量PSSize在模型中定义,将返回CMS中设置的数字。

【问题讨论】:

  • 这就是 PaginationSummary 上下文。为什么要改呢?
  • 嗨,取决于我放的数字...假设我放了 PaginationSummary(5).. 分页将如下所示:« prev | 1 ... 9 10 11 12 13 ... 18 |下一个 » 好像我把 PaginationSummary(3) 放在哪里,它看起来像这样: « prev | 1 ... 10 11 12 ... 18 |下一页 » 我想通过在我的 php 文件中定义变量来标准化所有分页的上下文大小

标签: templates silverstripe


【解决方案1】:

SS 2.4 模板语言的功能非常有限。

在这种特定情况下,您可以尝试在控制器中解决它 - 尝试调整 ProductListPage_Controller::ProductList 中的 $resultSet 以将分页摘要预处理为所需的上下文大小,以便稍后从模板中访问它。

试试这样的:

$resultSet->AdjustedPaginationSummary = $resultSet->PaginationSummary($this->productsPerPage);
return $resultSet;

然后在模板中你应该可以做到:

<% control ProductList.AdjustedPaginationSummary %>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 2013-03-28
    • 2015-05-02
    • 1970-01-01
    • 2012-08-14
    相关资源
    最近更新 更多