FIX: prevents rendering topic-category if empty (#9720)

FIX: prevents rendering topic-category if empty (#9720)

diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index 2d93468..954369a 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -1012,6 +1012,8 @@ class TopicsController < ApplicationController
 
     respond_to do |format|
       format.html do
+        @tags = SiteSetting.tagging_enabled ? @topic_view.topic.tags : []
+        @breadcrumbs = helpers.categories_breadcrumb(@topic_view.topic) || []
         @description_meta = @topic_view.topic.excerpt.present? ? @topic_view.topic.excerpt : @topic_view.summary
         store_preloaded("topic_#{@topic_view.topic.id}", MultiJson.dump(topic_view_serializer))
         render :show
diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb
index 801e0a0..2c6f271 100644
--- a/app/views/topics/show.html.erb
+++ b/app/views/topics/show.html.erb
@@ -4,9 +4,8 @@
       <%= render_topic_title(@topic_view.topic) %>
     </h1>
 
-    <div class="topic-category" itemscope itemtype="http://schema.org/BreadcrumbList">
-      <% @breadcrumbs = categories_breadcrumb(@topic_view.topic) %>
-      <% if @breadcrumbs.present? %>
+    <% if @breadcrumbs.present? || @tags.present? %>
+      <div class="topic-category" itemscope itemtype="http://schema.org/BreadcrumbList">
         <% @breadcrumbs.each_with_index do |c, i| %>
           <span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
             <a href="<%= Discourse.base_url %><%= c[:url] %>" class="badge-wrapper bullet" itemprop="item">
@@ -16,10 +15,7 @@
             <meta itemprop="position" content="<%= i + 1 %>" />
           </span>
         <% end %>
-      <% end %>
 
-      <% if SiteSetting.tagging_enabled %>
-        <% @tags = @topic_view.topic.tags %>
         <% if @tags.present? %>
           <meta itemprop='keywords' content='<%= @tags.map(&:name).join(', ') %>'>
           <div class='discourse-tags list-tags'>
@@ -28,8 +24,8 @@
             <% end %>
           </div>
         <% end %>
-      <% end %>
-    </div>
+      </div>
+    <% end %>
   </div>
 
   <%= server_plugin_outlet "topic_header" %>

GitHub sha: addf9d62

This commit appears in #9720 which was approved by udan11. It was merged by udan11.