- Issue created by @chike
- Status changed to Needs review
over 1 year ago 8:01am 19 July 2023 - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
I think you could do this in forums.html.twig if the topics variable was empty
{% if topics is empty %} <p>Hey, no topics exist yet, please check back soon thanks π</p> {% else %} // existing twig code {% endif %}
- π³π¬Nigeria chike Nigeria
I fiddled a bit with forums.html.twig before posting. The problem is the message equally shows up on containers where topics exist in some of the forums and some forums are empty.
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
You might be able to check
term.forum_container.value
orterm.get('forum_container').value
If its true, then its a container so you could skip the message.
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Oh, and if that doesn't work, you can implement
hook_preprocess_forums()
in your theme and create an 'is_container' flag.something like this
function YOURTHEME_preprocess_forums(&$variables) { $variables['is_container'] = $variables['term']->forum_container->value; }
Where YOURTHEME is your theme name and this file goes in your .theme file.
You would then have access to
is_container
in the twig file. - π³π¬Nigeria chike Nigeria
I created the
is_container
flag but problem was the/forum
path which returned0
as though it were a forum and all board was hidden.I tried to exclude the path in the preprocess function this way,
function custom_module_preprocess_forums(&$variables) { $current_path = \Drupal::service('path.current')->getPath(); if ($current_path != '/forum') { $variables['is_container'] = $variables['term']->forum_container->value; } }
and then this on the template file,
{% if topics is empty and is_container == '0' %} <p>Hey, no topics exist yet, please check back soon thanks π</p> {% else %} {% if forums_defined %} <div class="forum"> {{ forums }} {{ topics }} {{ topics_pager }} </div> {% endif %} {% endif %}
It is working this way.
Thanks.
- Status changed to Postponed
over 1 year ago 8:06pm 28 July 2023 - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Nice work!
I think it's worth adding the is container and an is root variable to the module itself but I want to wait until we get it removed from core first
Postponing for that
- Status changed to Active
11 months ago 7:30am 4 May 2024