Inicio › Toolset Professional Support › [Resuelto] Conditionals view loop
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Kolkata (GMT+05:30)
Este tema contiene 23 respuestas, tiene 2 mensajes.
Última actualización por hispavista-s.l.E hace 1 año, 8 meses.
Asistido por: Minesh.
Hello,
I have created a content template that generates a table. I need to add a conditional on the th outside the loop so that only when the related fields of the loop with that th have content the corresponding th is displayed.
I can't generate a conditional that does it. This is the code:
<table width="100%" class="table table-borderless table-light table-sm">
<thead>
<tr class="bg-light">
<th scope="col" class="p-0 border-0">Asignatura</th>
[wpv-conditional if="( '[types field='semestre-tabla']' eq '' )" evaluate="false"]
<th scope="col" class="text-center border-0">Semestre</th>[/wpv-conditional]
[wpv-conditional if="( '[types field='creditos-ects-tabla']' eq '' )" evaluate="false"]
<th scope="col" class="text-center border-0">Crédicos ECTS</th>[/wpv-conditional]
[wpv-conditional if="( '[types field='horas-tabla']' eq '' )" evaluate="false"]
<th scope="col" class="text-center border-0">Horas</th>[/wpv-conditional]
</tr>
</thead>
<tbody class="wpv-loop js-wpv-loop">
<wpv-loop>
<tr class="bg-light">
<td class="bg-light p-0">[types field="asignatura-tabla"][/types]</td>
<td class="bg-light text-center p-0">[types field="semestre-tabla"][/types]</td>
<td class="bg-light text-center p-0">[types field="creditos-ects-tabla"][/types]</td>
<td class="bg-light text-center p-0">[types field="horas-tabla"][/types]</td>
</tr>
</wpv-loop>
How can I generate these conditions?
I really need to solve this problem.
I look forward to your answer.
Best regards and thanks
Hello. Thank you for contacting the Toolset support.
There is no way to compare the field value outside the views loop.
You may use custom CSS that should help in this case. Please check the following article:
- https://stackoverflow.com/questions/5172454/remove-hide-tables-empty-columns-including-th
Or you can create a shortcode that should return true if value is present for that custom field and use that cusotm shortcode with your conditional statement.
More info:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/how-to-create-a-custom-shortcode/
Hi Minesh, sorry for taking so long to reply, I have been trying what you are telling me.
None of these solutions you send me work for me. I don't know if you could help me to achieve what I need.
Can you please share problem URL and admin access details and let me see if I can able to share any workaround.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Can you please share details on what post/page you added the view?
Hello Minesh,
It is an elementor saved template called "FORMACIÓN – Listado de cursos".
You can view the results on the front end in any of the "ESTUDIOS" listed in the menu.
Best regards and thanks
I've added the following custom JS code to your view's Javascript editor:
jQuery(document).ready(function($){ $('table').each(function(a, tbl) { var currentTableRows = $(tbl).find('tr').length - 1; console.log(a+"==="+currentTableRows); $(tbl).find('tr td').each(function(i) { if($(this).html()=='') { $(this).remove(); } }); });
I can see it removes the empty tds.
Hello Manish,
I have checked and the code still shows th that do not contain tds.
In the example in the screenshot the th for "Horas" should not come up.
can you please create the following response as private?
I'm checking with the following link:
=> enlace oculto
With the section "PLAN DE ESTUDIOS" and under the accordion "PRIMER CURSO" I can not see the said th "Horas".
Can you please tell me where exactly I can see that?
Hello Manish,
Please reload because it does show.
can you please create the following response as private?
Can you please check now:
I've added the following custom JS code to your view's custom JS section:
jQuery(document).ready(function($){ $('table').each(function(a, tbl) { var currentTableRows = $(tbl).find('tr:has(td)').length - 1; $(tbl).find('th').each(function(i) { var remove = 0; var currentTable = $(this).parents('table'); var tds = currentTable.find('tr.bg-light td:nth-child(' + (i + 1) + ')'); tds.each(function(j) { if (this.innerHTML == '') remove++; }); if (remove == currentTableRows) { $(this).hide(); tds.hide(); } }); });
Can you please confirm it works as expected now.
Hello Minesh,
Something very strange is happening to me. In the site where you have generated the js in the view it works, but when I move it to the final site it doesn't work. I have copied and pasted all the content of the view.
What could be happening?
I will have to check whats going wrong there and for that I will require your live site access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
My issue is resolved now.
Minesh is a great support technician. Thank you very much for your help.
Hello Minesh,
I have a question about the code you generated. I have been asked to remove the last tr and td from the table. When I delete it, the js code that I added to you stops working. I have tried to see how I could modify it, but impossible. even when I modify the conditional of those fields it stops working.
Could you help me?
Best regards and thanks