swig资料 | 关于swig在hexo中的判断

函数判断

1
2
{% if ····() %}
{% endif %}

····() 为有return true/false的函数

例(1)

1
2
3
{% if is_post() %}
<p>如果返回true,那么就显示这个段落</p>
{% endif %}

例(2)

1
2
3
4
5
6
7
8
9
{% if is_post() %}
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-edit"></i>
</span>
<span class="post-meta-item-text">
<a rel="nofollow" href="https://github.com/Mryan2005/mryan2005.github.io/blob/src/source{{url_for(page.source)}}">更改文章</a>
</span>
{% endif %}

如果没猜错的话这就是我的博客的文章更改传送门

变量判断

第一种

1
2
{% if x === '' %}
{% endif %}

第二种

1
2
{% if '' in x %}
{% endif %}