Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Twig 细枝一对多关系_Twig - Fatal编程技术网

Twig 细枝一对多关系

Twig 细枝一对多关系,twig,Twig,我是新手。我以为我已经掌握了基本知识,但我完全被困在这一点上了 我有两个阵列: books => [ [ 'book_id' => ..., 'book_title' => ..., ], ], 及 tags => [ [ 'tag_id' => ...,

我是新手。我以为我已经掌握了基本知识,但我完全被困在这一点上了

我有两个阵列:

books => [
             [
                 'book_id' => ...,
                 'book_title' => ...,
             ],
         ],  

tags => [
             [
                 'tag_id' => ...,
                 'book_id' => ...,
                 'tag'     => ...,
             ],
         ],  
我如何让细枝沿着这些线生产东西

书名1 tag1 tag2 tag3 tag5

书名2 tag1 tag3 tag4 tag2

等等

到目前为止我有

{% for book in books %}
    {{book.title}} 
    {% for tag in tags %}

what goes here to get a list of tags for this book

    {%endfor%}  
{% endfor %}
我知道这只是几行代码,但我不知道从哪里开始
如果能给您一个正确的提示,我们将不胜感激。

这样您就知道了书的id。您应该能够使用它来限制标签上的FOR循环:

{% for book in books %}
    {{book.title}} 
    {% for tag in tags if book.id == tag.id %}
       {{ tag.tag }}
    {%endfor%}  
{% endfor %}

请参阅:

非常感谢您的快速回复。你帮我省了好几个小时来解决这个问题。