John Davidson

php - Disable or hide EasyAdmin crud search bar

0 comments
Message:


I have developped an online learning website with EasyAdmin as backend. Everything works fine, but I'd like to hide or disable the search bar on top of the crud pages. I have not overridden any templates, just created crud based on my entities with fields and a custom query builder to only index content created by the logged in user.
Can't seem to find any info on how to do it online or in the doc. Is it possible to add an option to hide or disable the default search bar? Thank you!



My Answer:
To hide or disable the default search bar in EasyAdmin, you can override the default templates provided by EasyAdmin. Here's how you can do it:

1. Create a new directory in your project's templates directory called `easy_admin` if it doesn't already exist.

2. Inside the `easy_admin` directory, create a new directory called `crud`.

3. Inside the `crud` directory, create a new directory with the name of the entity for which you want to hide the search bar. For example, if you want to hide the search bar for the `User` entity, create a directory called `User`.

4. Inside the entity directory (`User` in this example), create a new file called `list.html.twig`.

5. In the `list.html.twig` file, add the following code to hide the search bar:

twig
{% extends '@EasyAdmin/crud/list.html.twig' %}

{% block search_form %}
{# Do nothing to hide the search bar #}
{% endblock %}


6. Save the file and clear the cache of your Symfony application by running `php bin/console cache:clear`.

Now, when you navigate to the CRUD pages for the `User` entity, the search bar should be hidden. Repeat the same steps for other entities if you want to hide the search bar for them as well.

Please note that this solution involves overriding the default templates provided by EasyAdmin, so make sure to keep an eye on any updates to EasyAdmin that may affect these customizations.

Rate this post

3 of 5 based on 9775 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us