将entry_id发送到ExpressionEngine中的嵌入
我正在尝试找到一个好的解决方案来解决我的页面标题问题。我从来没有在 EE 中完成它们的完美解决方案,尽管我最终认为我已经取得了突破,但我却碰壁了,希望你们中一位更有经验的表达式工程师能够提供帮助。
基本上我想做的是,在模板中输入页面主要内容的条目循环中,我想获取该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 代码中见过类似的东西。
I'm trying to find a good solution to my page title woes. I've never had a perfect solution for doing them in EE and though I'd finally thought I'd made a breakthrough I've hit a brick wall and hopefully one of you more experienced Expression Engine'ers might be able to help.
Basically what I'm trying to do is, where the entries loop that is feeding in the main content for a page in my template I want to grab that entry_id and feed it to the header file embed. I'm doing this in a way much like this...
{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>
The intention of this being that the id number gets passed to the header file where I can work my magic. What happens though is that as soon as I call {pre_eid} outside of that entries section it outputs the unparsed tag.
How can I go about sending that entry_id parsed to the header? I understand there is something I'm missing here in terms of parse order, or technique though I know I've seen something similar before on other EE code I've looked at.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关于此主题的之前的答案可能对您有帮助。
基本上,许多 Web 开发人员将使用 带有嵌入模板的嵌入变量 来传递 < code>{entry_title} 到全局嵌入模板,允许 动态页面标题:
如果您使用 EE2,SEO Lite模块用一行代码为您处理所有艰苦的工作:
另一个聪明的解决方案(/via Derek Hogue) 是换行页面的大部分内容都位于各个条目页面模板上的单个
{exp:channel:entries}
标记中,从而避免使用多个且昂贵的频道条目查询的开销:其他解决方案包括低标题插件(EE1、EE2)。
A previous answer on this topic may be helpful for you.
Basically, many Web Developers will use an Embed Variable with an Embedded Template to pass the
{entry_title}
to a global embed template, allowing for a dynamic page title:If you're using EE2, the SEO Lite Module takes care of all the hard work for you with a single line of code:
Another clever solution (/via Derek Hogue) is to wrap most of your page in a single
{exp:channel:entries}
tag on individual entry page templates, avoiding the overhead of using multiple and expensive channel entries queries:Other solutions include the Low Title Plugin (EE1, EE2).
{entry_id}
变量不在频道条目查询之外设置。您需要将其包含在开始和结束{exp:channel:entries}
标记之间。请尝试这样的操作:
顺便说一下,您使用的
{preload_replace}
模板标记变量在 EE1 中过去称为{assign_variable}
。预加载文本替换在模板解析接近结束时进行评估>,因此您不能使用它们来包含 EE 代码位。
另一方面,片段在模板开头附近进行解析< /em> 解析,因此它可能在其他方面对您有用。
Lodewijk Schutte 的 ExpressionEngine 解析顺序(PDF,32 KB) 拥有所有令人痛苦的细节。
The
{entry_id}
variable isn't set outside of a channel entries query. You need to include it between the openening and closing{exp:channel:entries}
tags.Try something like this instead:
Incidentally, the
{preload_replace}
template tag variable you're using used to be called{assign_variable}
in EE1.Preload Text Replacements are evaluated near the end of template parsing, so you can't use them to contain bits of EE code.
On the other hand, Snippets are parsed near the beginning of template parsing, so it might be useful to you in other ways.
Lodewijk Schutte's ExpressionEngine Parse Order (PDF, 32 KB) has all the excruciating details.