Hi I have the following code:
<div class="row-fluid">
<div class="span12">
<h3>Top 10 most popular</h3>
<ul>
{exp:channel:entries channel="faqs" dynamic="no" limit="10"}
<li><a href="{url_title_path='help'}">{title}</a></li>
{/exp:channel:entries}
</ul>
<h3>Answer to selected question</h3>
{exp:channel:entries channel="faqs" dynamic="yes" require_entry="yes" limit="1"}
{if no_results}
<p>Click a question above to see the answer here</p>
{/if}
{answer}
{/exp:channel:entries}
</div>
</div>
So as you can see I am looping through faqs twice. The first set it to get all of the questions and then if a user clicks on a question thats when the second loop should kick in to show them the answer. This works fine apart from the no results statement in the second loop doesn't work. It just never gets output. Anyone know why?
You'll have to add
require_entry="yes"
to your second loop in order for the no results to work.
See the docs here http://expressionengine.com/user_guide/modules/channel/channel_entries.html#require-entry
Since you mentioned in the comments that you are using Stash, this following should get no_results
working as expected. I've just tested this and it works for me.
Download the beta version of Stash here https://github.com/croxton/Stash/tree/dev (currently v2.3.5).
See the documentation on no_results_prefix on the GitHub page.
You did not show the surrounding Stash tag that wraps your template code, but assuming it is a stash:set
tag, update your template something like this:
{exp:stash:set name="page_content" no_results_prefix="stash"}
<div class="row-fluid">
<div class="span12">
[...]
<h3>Answer to selected question</h3>
{exp:channel:entries channel="faqs" dynamic="yes" require_entry="yes" limit="1"}
{!-- note prefix, which was defined in outer stash:set tag --}
{if stash:no_results}
<p>Click a question above to see the answer here</p>
{/if}
{answer}
{/exp:channel:entries}
</div>
</div>
{/exp:stash:set}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With