ExpressionEngine 在循环外显示频道内容

发布于 2024-10-18 14:10:52 字数 51 浏览 1 评论 0原文

我知道这听起来很疯狂,但我需要在表达式引擎通道模块的循环之外显示一些发布信息。这可能吗?

I know this sounds crazy, but I need to show some post information outside of the loop in the expression engine channel module. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

青萝楚歌 2024-10-25 14:10:52

您可以使用 EE 的 SQL 查询模板标签(如果您知道或有权访问数据库表名称并知道在数据库中查找什么内容):

http://expressionengine.com/user_guide/modules/query/index.html

基本上,您只输出您需要的内容 - 它不必属于到某个频道或任何特定的内容。一个困难是您必须了解 SQL 语法的基础知识,但如果您对它有一点应用知识,您就可以用它做很多其他事情。

You could use EE's SQL Query template tags (if you know, or have access to the database table names and know what to look for in the database):

http://expressionengine.com/user_guide/modules/query/index.html

Basically, you'd output only what you need - it doesn't have to belong to a channel, or anything specific. The one kicker is that you'd have to know the basics of SQL syntax, but if you have a small working knowledge of it, you can do tons of additional things with it.

誰ツ都不明白 2024-10-25 14:10:52

如果您不热衷于 SQL,您可以简单地将模板嵌入到您正在使用的模板中。下面是一个简单的示例,假设您正在名为 'news' 的模板组内编辑 indexmeta 模板:

index 模板内容:

{exp:channel:entries channel="news"}
  <div class="entry">
    <h1>{title}</h1>
    <div class="content">{body}</div>
    {embed="news/meta" this_entry_id="{entry_id}"}
  </div>
{/exp:channel:entries}

meta 模板内容:

{exp:channel:entries channel="news" dynamic="no" limit="1" entry_id="{embed:this_entry_id}"}
  <div class="meta">
    <p>{entry_date}</p>
    <p>{author}</p>
  </div>
{/exp:channel:entries}

如您所见,index 模板嵌入了meta 模板。请注意,我们将一个参数传递给 meta 模板,以便它知道要打印有关哪个条目 ID 的信息。如果您不熟悉 EE 的模板嵌入功能,可以在 EE 文档。在其他模板中嵌入模板是多次访问 {exp:channel:entries} 循环的好方法。

If you're not keen on SQL, you could simply embed a template within the template that you're working on. Here's a simple example that assumes you're editing the index and meta templates inside of a template group called 'news':

index template contents:

{exp:channel:entries channel="news"}
  <div class="entry">
    <h1>{title}</h1>
    <div class="content">{body}</div>
    {embed="news/meta" this_entry_id="{entry_id}"}
  </div>
{/exp:channel:entries}

meta template contents:

{exp:channel:entries channel="news" dynamic="no" limit="1" entry_id="{embed:this_entry_id}"}
  <div class="meta">
    <p>{entry_date}</p>
    <p>{author}</p>
  </div>
{/exp:channel:entries}

As you can see, the index template is embedding the meta template. Note that we're passing a parameter to the meta template so that it knows which entry ID to print information about. If you're unfamiliar with EE's template embedding feature, you can read more about it in the EE docs. Embedding templates in other templates is a great way to access the {exp:channel:entries} loop multiple times.

梦在深巷 2024-10-25 14:10:52

有一个名为 MX Jumper 的附加组件,它允许您从条目循环内部“设置”变量,然后在模板中的其他位置“获取”它(在 HTML 循环之前或之后并不重要,因为它会稍后解析)。

或者,现在流行的方法是使用附加 Stash 来存储您需要明确使用的任何和所有元素,作为您设置然后获取的存储变量 - 与上面类似,只是一旦设置它们,获取它们必须在稍后的解析阶段进行。这种方法的美妙之处在于,存储将存储“设置”变量以便在用户或站点级别重用,并且您可以确定到期期限,从而获得更好的性能。当您使用“模板部分”思维方式广泛应用这一点时,您可以使用存储存储所有内容,然后将它们调用到少量包装模板中。这使得可以使用 stash 来设置,例如,您的条目标题,然后在包装模板中单独获取它三次,而无需任何额外的负载 - 不需要在模板中进行单独的循环 - 一个循环来设置变量,然后您可以根据需要在模板中调用该变量 - 这有点像动态创建全局变量。

There's an add-on called MX Jumper that allows you to "set" a variable from inside your entries loop and then "get" it elsewhere in the template (before or after in the HTML loop doesn't matter because it parses later).

Alternatively, the approach that's all the rage now is to use the add-on Stash to store any and all elements you need to use distinctly as stash variables that you set and then get - similar to the above, except that once you set them, getting them has to happen at a later parsing stage. The beauty of this approach is stash will store the "set" variables for reuse either at a user or site level, and you can determine what the expiry period is - which then results in better performance. When you apply this broadly using the "template partials" mindset, you can store everything with stash, and then call them into a small number of wrapper templates. This makes it possible to use stash to set, for example, your entry title, then get it three separate times in the wrapper template without any additional load - no need for separate loops within your template - one loop to set the variable, and then you can call that variable as needed in your template - it's kind of like creating global variables on the fly.

通知家属抬走 2024-10-25 14:10:52

我还建议查看 Stash

I would also suggest looking at Stash.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文