草庐IT

php - ExpressionEngine:单项模板

coder 2024-01-04 原文

我创建了一个名为信用卡的 channel 。所以我创建了一个名为 credit-cards 的模板组,其索引循环遍历所有信用卡并输出它们。这方面工作正常,这是我在 credit-cards.group 文件夹中的 index.html 文件的代码:

         {exp:channel:categories category_group="1" style="linear" dynamic="no"}
                    <div class="card-list tab" id="{category_url_title}">
                        <h2 class="category-title">{category_name} Credit Cards</h2>
                        <div class="cards">
                            {exp:channel:entries channel="credit_cards" category="{category_id}" dynamic="no"}
                                <article>
                                    <h4><a href="{url_title_path='credit-cards'}">{title}</a><span class="web-exclusive">MBNA Website Exclusive</span></h4>
                                    <ul>
                                        <li class="col-img">
                                            <a href="{url_title_path='credit-cards'}"><img width="116" height="84" alt="MBNA Platinum Credit Card" src="../lib-ui/img/cards/core/core_116x84/mbna_platinum_card_116x84.png"></a>
                                        </li>
                                        <li class="col-bt">{balance_transfer_rate}</li>
                                        <li class="col-purchases">{purchases_rate}</li>
                                        <li class="col-features">{key_features}</li>
                                        <li class="col-apply">
                                            <a rel="blank" class="btn btn-success" href="{apply_url}">
                                                Apply Now<span class="hide"> for the {title}</span>
                                            </a>
                                            <a class="cta" href="{url_title_path='credit-cards'}">
                                                Learn more<span class="hide"> about the {title}</span>
                                            </a>
                                            <label class="mbna-credit-card checkbox" for="compare_1">
                                                <span tabindex="0">
                                                    <input type="checkbox" value="mbna-credit-card" id="compare_1">
                                                </span>
                                                <span class="hide"> Add the {title} to </span>Compare
                                            </label>
                                        </li>
                                    </ul>
                                    <p class="rep-ex">{representative_example}</p>
                                </article>  
                            {/exp:channel:entries} 
                        </div>
                    </div>
                {/exp:channel:categories}

所以我的问题是这样的。假设我有一张名为 visa 信用卡的信用卡,为其生成的 url 是/credit-cards/visa-credit-card。当我点击这个链接时,我又得到了我的索引页面。我在我的组中创建了另一个名为 single.html 的模板文件,其中包含输出一张信用卡的代码。看起来像这样:

<h1>Credit Card Page</h1>
{exp:channel:entries channel="credit_cards" limit="1"}
{if no_results}
{redirect="404"}
{/if}

那么如何让它使用这个模板文件来代替单个条目呢?

最佳答案

这实际上是一个很容易解决的问题。您正在做的是代码的第 5 行无法判断是否应该限制输入信息。使用 dynamic='no',您已经说过“EE,您不需要使用此处的 URL 来确定通过哪些条目来限制它”

我的建议是以下代码:

{if segment_2 == ""}
    {exp:channel:categories category_group="1" style="linear" dynamic="no"}
        <div class="card-list tab" id="{category_url_title}">
            <h2 class="category-title">{category_name} Credit Cards</h2>
            <div class="cards">
                {exp:channel:entries channel="credit_cards" category="{category_id}" dynamic="no" disable="category_fields|member_data|pagination|trackbacks"}
                    <article>
                        <h4><a href="{url_title_path='credit-cards'}">{title}</a><span class="web-exclusive">MBNA Website Exclusive</span></h4>
                        <ul>
                            <li class="col-img">
                                <a href="{url_title_path='credit-cards'}"><img width="116" height="84" alt="MBNA Platinum Credit Card" src="../lib-ui/img/cards/core/core_116x84/mbna_platinum_card_116x84.png"></a>
                            </li>
                            <li class="col-bt">{balance_transfer_rate}</li>
                            <li class="col-purchases">{purchases_rate}</li>
                            <li class="col-features">{key_features}</li>
                            <li class="col-apply">
                                <a rel="blank" class="btn btn-success" href="{apply_url}">
                                    Apply Now<span class="hide"> for the {title}</span>
                                </a>
                                <a class="cta" href="{url_title_path='credit-cards'}">
                                    Learn more<span class="hide"> about the {title}</span>
                                </a>
                                <label class="mbna-credit-card checkbox" for="compare_1">
                                    <span tabindex="0">
                                        <input type="checkbox" value="mbna-credit-card" id="compare_1">
                                    </span>
                                    <span class="hide"> Add the {title} to </span>Compare
                                </label>
                            </li>
                        </ul>
                        <p class="rep-ex">{representative_example}</p>
                    </article>  
                {/exp:channel:entries} 
            </div>
        </div>
    {/exp:channel:categories}
{/if}
{if segment_2}
    {exp:channel:entries channel="credit_cards" limit="1" disable="category_fields|member_data|pagination|trackbacks"}
        <article>
            <h4><a href="{url_title_path='credit-cards'}">{title}</a><span class="web-exclusive">MBNA Website Exclusive</span></h4>
            <ul>
                <li class="col-img">
                    <a href="{url_title_path='credit-cards'}"><img width="116" height="84" alt="MBNA Platinum Credit Card" src="../lib-ui/img/cards/core/core_116x84/mbna_platinum_card_116x84.png"></a>
                </li>
                <li class="col-bt">{balance_transfer_rate}</li>
                <li class="col-purchases">{purchases_rate}</li>
                <li class="col-features">{key_features}</li>
                <li class="col-apply">
                    <a rel="blank" class="btn btn-success" href="{apply_url}">
                        Apply Now<span class="hide"> for the {title}</span>
                    </a>
                    <a class="cta" href="{url_title_path='credit-cards'}">
                        Learn more<span class="hide"> about the {title}</span>
                    </a>
                    <label class="mbna-credit-card checkbox" for="compare_1">
                        <span tabindex="0">
                            <input type="checkbox" value="mbna-credit-card" id="compare_1">
                        </span>
                        <span class="hide"> Add the {title} to </span>Compare
                    </label>
                </li>
            </ul>
            <p class="rep-ex">{representative_example}</p>
        </article>  
    {/exp:channel:entries} 
{/if}

请注意,这不是 100% 准确,因为我删除了您的 exp:channel:categories 标签,但这应该让您得到一个基于缩短的 URL 限制的结果,就像您一样已经指定。

关于php - ExpressionEngine:单项模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13014024/

有关php - ExpressionEngine:单项模板的更多相关文章

  1. ruby - 通过 erb 模板输出 ruby​​ 数组 - 2

    我正在使用puppet为ruby​​程序提供一组常量。我需要提供一组主机名,我的程序将对其进行迭代。在我之前使用的bash脚本中,我只是将它作为一个puppet变量hosts=>"host1,host2"我将其提供给bash脚本作为HOSTS=显然这对ruby​​不太适用——我需要它的格式hosts=["host1","host2"]自从phosts和putsmy_array.inspect提供输出["host1","host2"]我希望使用其中之一。不幸的是,我终其一生都无法弄清楚如何让它发挥作用。我尝试了以下各项:我发现某处他们指出我需要在函数调用前放置“function_”……这

  2. ruby-on-rails - Mandrill API 模板 - 2

    我正在使用Mandrill的RubyAPIGem并使用以下简单的测试模板:testastic按照Heroku指南中的示例,我有以下Ruby代码:require'mandrill'm=Mandrill::API.newrendered=m.templates.render'test-template',[{:header=>'someheadertext',:main_section=>'Themaincontentblock',:footer=>'asdf'}]mail(:to=>"JaysonLane",:subject=>"TestEmail")do|format|format.h

  3. ruby - Chef Ruby 遍历 .erb 模板文件中的属性 - 2

    所以这可能有点令人困惑,但请耐心等待。简而言之,我想遍历具有特定键值的所有属性,然后如果值不为空,则将它们插入到模板中。这是我的代码:属性:#===DefaultfileConfigurations#default['elasticsearch']['default']['ES_USER']=''default['elasticsearch']['default']['ES_GROUP']=''default['elasticsearch']['default']['ES_HEAP_SIZE']=''default['elasticsearch']['default']['MAX_OP

  4. ruby - 如何通过Middleman安装和使用Slim模板引擎 - 2

    一般来说,我是Middleman和ruby​​的新手。我已经安装了Ruby我已经安装了Middleman和gem以使其运行。我需要使用slim而不是默认的模板系统。所以我安装了Slimgem。Slim的网站只说我需要'slim'才能让它工作。中间人网站说我只需要在config.rb文件中添加模板引擎,但是没有给出例子...对于没有ruby​​背景的人来说,这没有帮助。我在git上找了几个config.rb,它们都有:require'slim'和#Setslim-langoutputstyleSlim::Engine.set_default_options:pretty=>true#Se

  5. ruby-on-rails - 这个 C 和 PHP 程序员如何学习 Ruby 和 Rails? - 2

    按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。我来自C、php和bash背景,很容易学习,因为它们都有相同的C结构,我可以将其与我已经知道的联系起来。然后2年前我学了Python并且学得很好,Python对我来说比Ruby更容易学。然后从去年开始,我一直在尝试学习Ruby,然后是Rails,我承认,直到现在我还是学不会,讽刺的是那些打着简单易学的烙印,但是对于我这样一个老练的程序员来说,我只是无法将它

  6. ruby-on-rails - 如何将变量值插入 ERB 模板中的 HTML 标签? - 2

    我有一个偏爱:如何将像o.office这样的值插入到属性中?value="#{o.office}"无效。 最佳答案 'type='text'/>或者你可以使用表单助手 关于ruby-on-rails-如何将变量值插入ERB模板中的HTML标签?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/6172174/

  7. ruby - 输出液体模板中的可用对象和属性 - 2

    有没有办法在liquidtemplate中输出(用于调试/信息目的)可用对象和对象属性??也就是说,假设我正在使用jekyll站点生成工具,并且我在我的index.html模板中(据我所知,这是一个液体模板)。它可能看起来像这样{%forpostinsite.posts%}{{post.date|date_to_string}}»{{post.title}}{%endfor%}是否有任何我可以使用的模板标签会告诉我/输出名为post的变量在此模板(以及其他模板)中可用。此外,是否有任何模板标签可以告诉我post对象具有键date、title、url、摘录、永久链接等

  8. python - 图灵完备模板引擎 - 2

    很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭11年前。哪些模板引擎/模板语言是图灵完备的?到目前为止,我听说过这些:FreeMarker(用java实现)MovableTypes模板语言(perl)xslt:-(Cheetah(Python语言)聪明(PHP)还有其他的(特别是用perl实现的)吗?Ps:不要浪费时间向我解释MVC,以及为什么图灵完整模板不好,以及为什么这不是一个有用的比较点:)

  9. ruby - 迭代液体模板中的数组 - 2

    我知道我可以用这段代码迭代liquid模板中的数组:{%foriteminmyarray%}{{item.label}}但是我怎样才能得到我的项目在数组中的索引呢? 最佳答案 根据"LiquidforDesigners"liquid的github部分...forloop.length#=>lengthoftheentireforloopforloop.index#=>indexofthecurrentiterationforloop.index0#=>indexofthecurrentiteration(zerobased)forl

  10. ruby - 液体模板贴图过滤器 - 2

    究竟如何使用Liquid中的map过滤器?我在Jekyll中使用它。---my_array:[apple,banana,orage]my_map:hello:worldfoo:barmy_string:"howdoesthiswork?"---{{page.my_map|map...}}这就是我迷路的地方。我似乎无法在文档或任何其他在线网站上找到任何关于它的用法示例。顺便说一下,我还不懂Ruby,所以sourcecode我也不清楚。来自filtertests看起来下面应该产生一些东西,但在GitHub上,我什么也没得到:{{site.posts|map:'title'|array_to

随机推荐