Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/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
Templates 如何删除Stacey v3和Twig中第一页和最后一页上的上一页和下一页链接?_Templates_Hyperlink_Twig_Next - Fatal编程技术网

Templates 如何删除Stacey v3和Twig中第一页和最后一页上的上一页和下一页链接?

Templates 如何删除Stacey v3和Twig中第一页和最后一页上的上一页和下一页链接?,templates,hyperlink,twig,next,Templates,Hyperlink,Twig,Next,我正在编辑Stacey v3中的project.html模板,下一个和上一个链接由以下内容生成: {%include'partials/next page.html%} 及 {%include'partials/previous page.html%} 在下一页.html中: {% for sibling in page.next_sibling %} <li><a href="{{ sibling.url }}" title="{{ sibling.title }}"&g

我正在编辑Stacey v3中的
project.html
模板,下一个和上一个链接由以下内容生成:

{%include'partials/next page.html%}

{%include'partials/previous page.html%}

下一页.html
中:

{% for sibling in page.next_sibling %}
  <li><a href="{{ sibling.url }}" title="{{ sibling.title }}">Next project</a>: &rarr; {{ sibling.title }}</li>
{% endfor %}
{% for sibling in page.previous_sibling %}
  <li><a href="{{ sibling.url }}" title="{{ sibling.title }}">Previous project</a>: &larr; {{ sibling.title }}</li>
{% endfor %}
他们工作得很好,他们做得很好,我的问题是在第一个项目页面上,它有一个链接到上一个页面,如
  • :←
  • ,这是行不通的

    在它创建的项目的最后一页
  • :→
  • 这些我不想要的死链接,它们是误导和毫无意义的

    所以我试图用这样的逻辑来摆脱它们,如果是第一页,就不要生成上一个链接,在最后一页上也不要生成下一个链接

    我试过这样的方法:

    {% for sibling in page.siblings %}
        {% if loop.first == False %}
            Nothing should be generated
                {% else %}
            {% include 'partials/next-page.html' %}
        {% endif %}
    {% endfor %}
    

    这不起作用,我对逻辑的理解也不合理。

    事实上,我认为你在做与你想做的相反的事情:

    {% if loop.first == False %}
        Nothing should be generated
    
    你应该这么做

    {% if loop.first %}
        Nothing should be generated
    
    您希望在循环是第一个循环时应用它

    更新:尝试以下方法:

    {% for sibling in page.siblings %}
        {% if sibling is null %}
            Nothing should be generated
        {% else %}
            {% include 'partials/next-page.html' %}
        {% endif %}
    {% endfor %}
    
    第二次更新:似乎存在后端概念问题……如果页面不存在,则应呈现空。在这里,似乎是呈现一个带有空属性(url,title…)的页面对象。 它应该被修复。现在,这能起作用吗

    {% for sibling in page.siblings %}
        {% if (sibling.url is null) or (sibling.url is empty) %}
            Nothing should be generated
        {% else %}
            {% include 'partials/next-page.html' %}
        {% endif %}
    {% endfor %}
    

    将templates/partials/next-page.html的内容替换为:

    {% if page.is_last %}
    <p>&nbsp;</p>
    {% else %}
    {% for sibling in page.next_sibling %}
      <p><a href="{{ sibling.url }}">Next project</a>: &rarr; {{ sibling.title }}</p>
    {% endfor %}
    {% endif %}
    
    {% if page.is_first %}
    <p>&nbsp;</p>
    {% else %}
    {% for sibling in page.previous_sibling %}
      <p><a href="{{ sibling.url }}">Previous project</a>: &larr; {{ sibling.title }}</p>
    {% endfor %}
    {% endif %}
    
    {%if page.is_last%}
    

    {%else%} {page.next_sibling%} :&rarr;{{sibling.title}

    {%endfor%} {%endif%}


    将templates/partials/previous-page.html的内容替换为:

    {% if page.is_last %}
    <p>&nbsp;</p>
    {% else %}
    {% for sibling in page.next_sibling %}
      <p><a href="{{ sibling.url }}">Next project</a>: &rarr; {{ sibling.title }}</p>
    {% endfor %}
    {% endif %}
    
    {% if page.is_first %}
    <p>&nbsp;</p>
    {% else %}
    {% for sibling in page.previous_sibling %}
      <p><a href="{{ sibling.url }}">Previous project</a>: &larr; {{ sibling.title }}</p>
    {% endfor %}
    {% endif %}
    
    {%if page.is_first%}
    

    {%else%} {page.previous_sibling%} :&larr;{{sibling.title}

    {%endfor%} {%endif%}
    它现在重复下一页链接的次数与我拥有的项目数量一样多:(它仍然在重复:(奇怪。你能做一个
    {dump(sibling)}
    {page.sibles%}{dump(sibling)}{%endfor%}
    函数“dump”在“project.html”中不存在在第54行Oh.你知道你正在使用的小树枝版本吗?嗯……实际上默认情况下它不可用。