Is there in the Symfony ecosystem an existing tool specifically meant to find unused Twig layouts, i.e. all layout files which are not included / embedded in other layouts nor rendered by any controller in the project?
After a huge frontend refactoring task on a big project, it may take a while and/or some trial-and-error sessions to find which layout files are not used anymore.
I was wondering if there is an existing tool / command that shows a list of (possibly) unused layout files. Of course layout names can be dynamically created so the list would still need to be carefully checked, but still it seems like that could save some time.
Thank you in advance for any answer.
Based on the docs (https://symfony.com/doc/current/index.html) the answer is no there is no tool/feature to find unused templates in symfony even if there may be other methods to find them.
In my quest, I finally made a script to find twig templates not referenced in templates/ or src/ files:
APP_PATH=./$1
TWIG_PATH=${APP_PATH}/templates
# find all files in TWIG_PATH, remove TWIG_PATH from the string
for i in $( find $TWIG_PATH -type f -not -path '*/\.*' -exec echo {} \; | cut -b $((${#TWIG_PATH}+2))- ); do
# search for the path in src and templates
if ! grep "$i" ${APP_PATH}/src ${APP_PATH}/templates -r -hc -m1 | grep -qv 0
then
echo $i;
fi
done
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