0

I have a markdown file in Hexo with the following in the front matter:

---
title: something blog post
tags:
  - local
  - world
categories:
  - news
date: 2016-07-27 15:08:51
twitter: twittername
facebook:
---

I have added two test variables (twitter and facebook) but is there a way to not output the content from the variable if the variable has not been set?

This is what is outputted from the HTML:

<ul id="social-links">
  <li class="twitter"><a href="http://twitter.com/twittername" target="_blank">twittername</a></li>
  <li class="facebook"><a href="http://facebook.com/" target="_blank"></a></li>
</ul>

Since the facebook variable was not filled you see nothing, this is breaking my layout since some posts will not have facebook or twitter and so on.

Thanks in advance

1 Answers1

2

with multiple if statements :

<% if (page.twitter || page.facebook) { %>
  <ul id="social-links">
    <% if (page.twitter) { %>
      <li class="twitter">
        <a href="http://twitter.com/<%= page.twitter %>" target="_blank">
          <%= page.twitter %>
        </a>
      </li>
    <% } %>
    <% if (page.facebook) { %>
      <li class="facebook">
        <a href="http://facebook.com/<%= page.facebook %>" target="_blank">
          <%= page.facebook %>
        </a>
      </li>
    <% } %>
  </ul>
<% } %>
Louis Barranqueiro
  • 10,058
  • 6
  • 42
  • 52