【问题标题】:Silverstripe 3: How to get images from multiple pages for display on another page in a function?Silverstripe 3:如何从多个页面获取图像以显示在函数中的另一个页面上?
【发布时间】:2014-01-11 17:13:24
【问题描述】:

我有一个 PageType - “GalleryPage”。这些页面中有很多,每个页面都有一个名为“$ClientLogo”的图像。如何编写一个函数来调用所有这些 ClientLogo 图像并将它们整理到单独的页面“ClienListPage”上。

类似于Silverstripe 3: create page control function to get images from grandchild pages and sort all randomly 但不是针对特定页面类型的子页面。

【问题讨论】:

    标签: image function silverstripe


    【解决方案1】:

    如果您的图库页面都是您的客户列表页面的子页面,您可以在Children 上致电loop 并检索每个ClientLogo

    ClientListPage 模板

    <% loop $Children %>
        $ClientLogo
    <% end_loop %>
    

    如果您的图库页面不是您的客户列表页面的所有子页面,您将需要在控制器中创建一个函数来获取所有图库页面以循环访问它们。

    ClientListPage 控制器

    private static $allowed_actions = array (
        'GalleryPages'
    );
    
    function GalleryPages()
    {
        $galleryPages = GalleryPage::get();
        return $galleryPages ? $galleryPages : false;
    }
    

    ClientListPage 模板

    <% loop $GalleryPages %>
        $ClientLogo
    <% end_loop %>
    

    【讨论】:

      猜你喜欢
      • 2018-04-22
      • 2013-08-11
      • 1970-01-01
      • 1970-01-01
      • 2020-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      相关资源
      最近更新 更多