Add a message on forums with no topics yet

Created on 13 July 2023, 12 months ago
Updated 4 May 2024, about 2 months ago

It will help to have a placeholder message on forums with no topics yet. Something like,

No topics posted yet in {{ forum.label }}. You can login using the button above and be the first to post a topic in {{ forum.label }}.

I think this will be more friendly than letting the user bump on a blank page.

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡³πŸ‡¬Nigeria chike Nigeria

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @chike
  • Status changed to Needs review 11 months ago
  • πŸ‡¦πŸ‡Ί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 or term.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 returned 0 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 11 months ago
  • πŸ‡¦πŸ‡Ί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

  • πŸ‡³πŸ‡¬Nigeria chike Nigeria

    Okay.

  • Status changed to Active about 2 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
Production build 0.69.0 2024