【问题标题】:Sending an entry_id to an embed in ExpressionEngine将 entry_id 发送到 ExpressionEngine 中的嵌入
【发布时间】:2012-01-17 15:28:55
【问题描述】:

我正在尝试为我的页面标题问题找到一个好的解决方案。我从来没有一个完美的解决方案可以在 EE 中完成它们,尽管我最终认为我已经取得了突破,但我还是碰壁了,希望你们中的一位更有经验的 Expression Engine'ers 能够提供帮助。

基本上我要做的是,在我的模板中为页面提供主要内容的条目循环中,我想获取该 entry_id 并将其提供给嵌入的头文件。我这样做的方式很像这样......

{embed="main/.header" pre_eid="{entry_id}"}

<div id="content">              
    {exp:channel:entries channel="standard-content" url_title="{segment_1}" limit="1"}

        {preload_replace:pre_eid="{entry_id}"}  

        <h1>{title}</h1>
        {content}

    {/exp:channel:entries}
</div>      

这样做的目的是将 id 号传递给头文件,我可以在其中发挥我的作用。但发生的情况是,只要我在该条目部分之外调用 {pre_eid} ,它就会输出未解析的标签。

如何将解析后的 entry_id 发送到标题?我知道在解析顺序或技术方面我在这里遗漏了一些东西,尽管我知道我以前在我看过的其他 EE 代码上看到过类似的东西。

【问题讨论】:

    标签: templates expressionengine


    【解决方案1】:

    关于此主题的previous answer 可能对您有所帮助。

    基本上,许多 Web 开发人员将使用Embed Variable with an Embedded Template{entry_title} 传递给全局嵌入模板,从而允许dynamic page title

    <html lang="en">
    <head>
        <meta charset="utf-8" />
    
        {embed="includes/header"
            title="
                {exp:channel:entries channel="{channel_name}"}
                    {title}
                {/exp:channel:entries}
            "
        }
    </head>
    

    如果您使用的是 EE2,SEO Lite Module 只需一行代码即可为您处理所有繁重的工作:

    <html lang="en">
    <head>
        <meta charset="utf-8" />
        {exp:seo_lite url_title="{url_title}"}
    </head>
    

    另一个聪明的解决方案(/通过Derek Hogue)是将您的大部分页面包装在单个条目页面模板上的单个{exp:channel:entries}标签中,避免使用多个和昂贵的频道条目的开销查询:

    {exp:channel:entries channel="channel_name" limit="1"}
        {embed="includes/header" title="{title}"}
    
        <h1>{title}</h1>
        {page_content}
    
        {embed="includes/footer"}
    
        {if no_results}{redirect="404"}{/if}
    {/exp:channel:entries}
    

    其他解决方案包括Low Title Plugin(EE1, EE2)

    【讨论】:

      【解决方案2】:

      {entry_id} 变量未在频道条目查询之外设置。您需要将它包含在打开和关闭{exp:channel:entries} 标记之间。

      试试这样的:

      {exp:channel:entries channel="channel_name" url_title="{segment_1}" limit="1"}
          {embed="main/.header" pre_eid="{entry_id}"}
      
          {preload_replace:pre_eid="{entry_id}"}
          ...
      {/exp:channel:entries}
      

      顺便提一下,您使用的 {preload_replace} 模板标签变量在 EE1 中曾被称为 {assign_variable}

      Preload Text Replacements模板解析结束时进行评估,因此您不能使用它们来包含一些 EE 代码。

      另一方面,Snippets 被解析在模板解析的开头,因此它可能在其他方面对您有用。

      Lodewijk Schutte 的 ExpressionEngine Parse Order(PDF, 32 KB) 包含所有令人痛苦的细节。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-03-26
        • 1970-01-01
        • 2018-02-13
        • 2018-05-30
        • 1970-01-01
        • 2022-07-16
        • 1970-01-01
        • 2020-07-29
        相关资源
        最近更新 更多