开发者

"no_entries" conditional logic

Is this possible to do the following in ExpressionEngine: (code taken from here)

IF THERE ARE RELATED ENTRIES SHOW THIS: (important to see the header)

HEADING : Related Entries:

    开发者_如何学C
  1. Entry 1

  2. Entry 2

  3. Entry 3

ELSE (SHOW NOTHING) ...

DONE

Code:

{related_entries id="performers"} 
{if no_related_entries} 
<h2>No Entries</h2>  {/if} 
<h2>{title}</h2>  {body}
{/related_entries}

How do I hide the header? Because the only way to check if there are related entries is to actually start the {related_entries} LOOP.

Any hints? I don't want to hack into PHP for this.


{related_entries id="performers"}
{if title != ""}
 <h2>{title}</h2>
{/if}
 {body}
{/related_entries}

This should do it, no need for no_related_entries, since you do not plan on doing anything if there is nothing.

Since you have header tags around your title, I imagine you want to avoid printing out header tags when there isn't any related entries.

so if title is not empty, display, if it is, then it won't, so you'll avoid <h2></h2>

don't worry about putting a conditional around the body tag, it will just not display anything if it is blank, but if you put an html tag around it like you did the title, then you would do the same as you do w/ the title conditional.


This ought to do the trick

{related_entries id="performers"} 
{if no_related_entries} 
    <h2>No Entries</h2>
{if:else}
    <h2>{title}</h2>  {body}
{/if} 
{/related_entries}

Sam "SammyTheSnake" Penny

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜