0

with_scope###ロコモティブ CMS での使用について質問があります。

まずmovies、完全なフィールドを持つモデル があり、そのうちの 1 つがfilm_etatswithで呼び出されtype: belongs_toます。

別のモデルfilm_etatsがあり、のetatフィールドtype: stringと の別のフィールドmoviesがありtype: has_manyます。

これで問題なく動作します - 自分のデータを見ることができます - しかし、やりたいことは情報をフィルタリングすることです。

Locomotive CMS のドキュメントには、 https ://doc.locomotivecms.com/docs/tags#with_scope があります。

これが最初の例です。

{% with_scope author: 'John Doe' %}
    {% for post in content_type.posts %}
        {{ post.title }}
    {% endfor %}
{% endwith_scope %}

だから私はこれをしました:

{% with_scope film_etats.etat: 'Production' %}
    {% for film in contents.film %}
        etat du film : {{film.film_etats.etat}}
    {% endfor %}
{% endwith_scope %}

しかし、それは機能せず、私が望むものは型エラーです:nilの未定義メソッド「エントリ」:NilClass

私のモデル映画

title_film => type (string)
film_etats => type belongs_to

私のモデル film_etats

etat => type(string)
films => type(has_many)

ありがとう

4

1 に答える 1

1

まず第一に、あなたのコードは少し奇妙です。それが機能したとしても、"Production" という単語のリストを何度も出力するだけだからです。すなわち

etat du film : Production
etat du film : Production
etat du film : Production
....

with_scope機能しない理由は、関連するモデルのフィールドに基づいてフィルタリングするために使用できないためです。次のコードは、制作中のすべての映画のタイトルを出力します。

{% with_scope etat: 'Production' %}
    {% assign production = contents.film_etats.first %}
{% endwith_scope %}

Production Films:<br />
{% for film in production.films %}
    - {{ film.title_film }}<br />
{% endfor %}
于 2013-10-14T01:05:06.857 に答える