【问题标题】:OctoberCMS - Overridden Blog Component (Rainlab Blog) Multiple Usage in Same PageOctoberCMS - 覆盖博客组件(Rainlab 博客)在同一页面中多次使用
【发布时间】:2019-06-24 15:38:32
【问题描述】:

我是 OctoberCMS 的新手,现在被卡住了,我在同一页面中多次使用我的自定义博客文章组件(它会覆盖 Rainlab 博客文章)时遇到问题。

假设我已经为 postLists 创建了默认 blogPosts 的别名,并且我定义了我的自定义 HTML 结构,它运行良好,没有问题。

现在我想要在我的页面中将 postLists 帖子结构用于三个不同的类别,在这里我被卡住了,因为当我将变量传递给这样的组件时 - { % component 'postLists' categoryFilter='news' %} 它不起作用对于类别过滤器,如果我从拖放组件 UI 中选择一个类别,它将成为页面的全局 categoryFilter 设置。

这是我的要求。

我的postList组件代码:-

{% set posts = __SELF__.posts %}
{% for post in posts %}

<div class="col-sm-6">
      <div class="row">
        <div class="col-sm-4 col-4 content_body_img">
            <a href="{{ post.url }}">
        {% if post.featured_images.count > 0 %}
            <img class="media-object" src="{{ post.featured_images.first.getThumb(108, 108) }}" />
        {% else %}
            <img class="media-object" src="http://placehold.it/108x108" />
        {% endif %}
    </a>
        </div>
        <div class="col-sm-8 col-8">
          <p><a href="{{ post.url }}">{{ post.title }}</a></p>
          <!--location_date-->
          <div class="location_date">
            <ul>
              <li><i class="fa fa-calendar"></i><span> {{ post.published_at|date('j F, Y') }}<span></li>
              <li><i class="fa fa-map-marker"></i>Dubai</li>
            </ul>
          </div>
          <!--location_date end -->
        </div>
      </div>
    </div>
    <!--content_body_img end -->
{% else %}
<div class="col-sm-6 col-6 col-lg-3">{{ noPostsMessage }}</div>
{% endfor %}

请帮助我,任何帮助将不胜感激。

谢谢桑尼

【问题讨论】:

  • 请发布组件代码
  • @NileshYadav 添加组件代码
  • 另外请发布组件php

标签: php laravel octobercms octobercms-plugins twig-extension


【解决方案1】:

这是静态方法 - 我将发布动态方法以及给我一些时间

最好且可能最简单的解决方案是(如果您只想显示帖子)是为每个标签添加 3 Post List component 和 Different Category filter 选项。

它应该做你的工作

如果您只需要显示列表,请确保这是最佳解决方案。

【讨论】:

  • 感谢您的时间和回复,这是我想到的第一件事,但我无法使用此方法,因为我为 blogPosts 及其别名创建了一个部分(覆盖默认 blogPosts 部分 html)是 postList (在您的示例中为 blogPostsFood),如果我更改别名,我将无法使用我的自定义帖子循环结构。请让我知道这对您是否有意义,或者您对此场景有解决方案。
  • 是的,我也得到了,所以检查我们是否可以使它成为动态方法
  • 运气好@Hardik?
  • 对不起,我试过了,但没有运气,我需要努力,但目前没有时间:(
猜你喜欢
  • 2019-08-24
  • 2019-07-02
  • 2017-05-23
  • 2018-06-17
  • 2012-11-22
  • 2017-08-16
  • 2017-07-26
  • 2020-02-25
  • 2018-04-20
相关资源
最近更新 更多