Projet-Symfony/templates/search/search.html.twig
2024-02-22 16:03:23 +01:00

59 lines
1.8 KiB
Twig
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{% extends 'base.html.twig' %} {% block title %} results for {{ query }} !{%
endblock %} {% block body %}
<script>
function addToFavs(id) {
// alert(id);
// /favorite/add/{id}
fetch("/favorite/add/" + id).then((data) => {
if (data.status == 200) {
document.querySelector("#id" + id).classList.add("fav");
alert("Added to favs");
}
});
}
</script>
<main id="searchResults">
<h1>Results for "{{ query }}" with {{fruit_emoji}}:</h1>
<div class="results">
{% for result in results %} {% set array = result['title']|split('-') %}
{% set artist = array[0] %} {% set album = array[1] %}
<section
class="album {% if result['isLiked'] == 'true' %}fav{% endif %}"
id="id{{result['id']}}"
>
<span>
<h2>{{album}}</h2>
by
<h3>{{artist}}</h3>
</span>
<img
loading="lazy"
src="{{result['cover_image']}}"
alt="{{album ~ ' by ' ~ artist}}"
/>
{% if result['isLiked'] == 'true' %}
<p>
<b>Already fav</b>, go to
<a href="{{url('app_favorite')}}">favorites</a>
</p>
{% else %}
<button onclick="addToFavs({{result['id']}})">
Add to favorites
</button>
{% endif %}
</section>
{% endfor %}
</div>
<nav>
<a
href="/search?q={{query}}&page={{previous_page}}&fruit={{fruit_emoji}}"
> previous page</a
>
<p>{{page}}</p>
<a href="/search?q={{query}}&page={{next_page}}&fruit={{fruit_emoji}}"
>next page </a
>
</nav>
</main>
{% endblock %}