Rendering data from a specific topic

You can fetch any single topic by inserting into the html the following code:

<% get_topic_view('english-glossary', opts: { include_suggested: false, include_related: false, post_number: 1 }, instance_var: "glossary", set_page_title: true) %>

The data will be stored in a local variable called glossary because it is defined in instance_var. To call the topic_view you use @glossary. You can access and display the data with a similar code as the following:

<% if @glossary.present? %>
  <div class="title-container" <% unless mobile_view? %> <% end %>">
    <div class="contents canvas">
      <h1 title="<%= @glossary.title %>" class="title"><%= @glossary.title %></h1>
			<section class="topic-byline">
			  <div class="date" title="<%= short_date(@glossary.topic.updated_at) %>">
			    Updated at: <%= short_date(@glossary.topic.updated_at) %>
			  </div>
			</section>
    </div>
  </div>
<% end %>

<% if @glossary.present? %>
  <article class="post">
    <div class="container">
			<section class="post-content canvas">
        <%= ::LandingPages::Post.html(@glossary.posts.first).html_safe %>
      </section>
			<%- if current_user %>
	      <div class="comment-container">
	        <div class="comment-footer">
	          <a class="btn btn-primary" href="/w/glossary-suggestion" targe="_blank">Suggest a term</a>
	        </div>
	      </div>
			<%- end %>
    </div>
  </article>
<% end %>

In this case, I use @glossary.topic.updated_at but you can access any other topic property as well.

You can also access the data for an entire list of topics and displaying by using:

<% topic_list(list_opts: { order: 'date', category: 'news', no_definitions: true }, opts: { instance_var: "news"}) %>

<% @news.each do |article| %>
  <li style="display: flex; margin:10px">
	<a href="<%= article.url %>" class="item" target="_blank">
		<div class="item-title">
			<%= short_date(article.created_at) %><br>
			<%= emoji_codes_to_img(article.fancy_title) %>
		</div>
	        <% if article.image_url.present? %>
			<div class="item-image">
			    <img src="<%= article.image_url %>" />
			 </div>
		<% end %>
	</a>
  </li>
<% end %>

Hope this helps.