Original Code:
<div class="our-story search-query">
<div class="container">
<h1>Search Results</h1>
{% if keysearch %}
<p>{{ view.total_rows }} results found for '<span class="font-500">{{ keysearch }}</span>'</p>
{% endif %}
</div>
</div>
I have this code in a twig file. I need to put in a condition:
1. If search results are ZERO, then it should say "No results found for 'YYY' "
2. If results are found i.e above Zero, then it should say " XX results found for 'YYY' "
Code with If condition:
{% if keysearch %}
{% set variable = {{ view.total_rows }} %}
{% if variable > 0 %}
<p>{{ view.total_rows }} results found for '<span class="font-500">{{ keysearch }}</span>'</p>
else {
<p>No results found for '<span class="font-500">{{ keysearch }}</span>'</p>
}
{% endif %}
When I put in a condition under `{% if keysearch %} it throws an error:
Twig_Error_Syntax: A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{" in "themes/custom/iifl/templates/views/views-view--search-page.html.twig" at line 59. in Twig_ExpressionParser->parseHashExpression() (line 281 of vendor\twig\twig\lib\Twig\ExpressionParser.php).
Can someone help me out.
{% set variable = {{ view.total_rows }} %}
needs to be{% set variable = view.total_rows %}