【问题标题】:JBake Templates: highlight latest postJBake 模板:突出显示最新帖子
【发布时间】:2015-12-12 16:26:57
【问题描述】:

我是 JBake 的新手。我看到了创建索引页面的默认方式。

<#list posts as post>
                <#if (post.status == "published")>
                                -- design your posts here
                </#if>
            </#list>

这会按降序拉出所有帖子。

这看起来很棒,只有一个问题,我不知道如何突出显示我的最新帖子。

所以我想做类似的事情,

<#list posts as post>
                <#if (post.status == "published")>
                               <#if (this is latest post)>
                                           use highlighted style
                                       </#if>
                                        <#if (this is not a latest post)>
                                           use normal style
                                       </#if>
                </#if>
            </#list>

我怎样才能做到这一点?

【问题讨论】:

    标签: freemarker jbake jbake-templates


    【解决方案1】:

    这是适用于 JBake v2.4.0 的一种解决方案:

            <#list posts as post>
                <#if (post.status == "published")>
                    <#if (post_index == 0)>
                        //apply highlight style
                    <#else>
                        //apply normal style
                    </#if>
                </#if>
            </#list> 
    

    为了加快页面的渲染速度,您也可以使用published_posts 变量:

            <#list published_posts as post>
                <#if (post.status == "published")>
                    <#if (post_index == 0)>
                        //apply highlight style
                    <#else>
                        //apply normal style
                    </#if>
                </#if>
            </#list> 
    

    如果您将 JBake 更新为使用 Freemarker v2.3.23,则可以使用 post?is_first 而不是 post_index == 0

    【讨论】:

    • 太好了,您能否分享一个教程链接,我可以在其中阅读有关这些模板的更多信息。
    • 对于 Freemarker,最好的办法是参考官方docs
    猜你喜欢
    • 2019-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多