{% if section.blocks.size > 0 %}
  	{% assign blog_handle = blog.handle %}
	{% for block in section.blocks %}
		{% if block.type == 'blog_tags' %}
			
				<div class="blog_sidebar_item">
                    {% if block.settings.title != blank %}
                    	<h{{ settings.blog_sidebar_heading_tag }} class="sidebar_title">{{ block.settings.title }}</h{{ settings.blog_sidebar_heading_tag }}>
                  	{% endif %}
                    <ul class="sidebar_menu_list">

                      	{% for tag in blog.all_tags %}
                            <li>
                                 <a href="{{ shop.url}}/blogs/{{ blogs[blog_handle].handle }}/tagged/{{ tag | handleize }}" title="{{ blogs[blog_handle].title }} {{ 'blogs.general.tagged' | t }} {{ tag | escape }}">{{ tag }}</a>
                            </li>
                        {% endfor %}
                    </ul>
                </div>
			
		{% endif %}

		{% if block.type == 'menu' %}
			{% if block.settings.menu != blank %}
				<div class="blog_sidebar_item">
                    <h{{ settings.blog_sidebar_heading_tag }} class="sidebar_title">{{ linklists[block.settings.menu].title }}</h{{ settings.blog_sidebar_heading_tag }}>
                    <ul class="sidebar_menu_list">
                        {% for link in linklists[block.settings.menu].links %}
                            <li><a href="{{ link.url }}">{{ link.title }}</a></li>
                        {% endfor %}
                    </ul>
                </div>
			{% endif %}
		{% endif %}
		{% if block.type == 'image' %}

          <div class="blog_sidebar_item">
            {% if block.settings.title != blank %}
            	<h{{ settings.blog_sidebar_heading_tag }} class="sidebar_title">{{ block.settings.title }}</h{{ settings.blog_sidebar_heading_tag }}>
            {% endif %}
            <img src="{{ block.settings.image | img_url:'' }}">
          </div>

		{% endif %}
		{% if block.type == 'recent_posts' %}
			<div class="blog_sidebar_item">
              {% if block.settings.title != blank %}
                  <h{{ settings.blog_sidebar_heading_tag }} class="sidebar_title">{{ block.settings.title }}</h{{ settings.blog_sidebar_heading_tag }}>
              {% endif %}
              <ul class="sidebar_recent_posts sidebar_menu_list">
                {% for article in blog.articles limit: block.settings.blog_post_count %}
                  <li>
                    <a href="{{ article.url }}" title="{{ article.title | escape }}">{{ article.title }}</a>
                    
                  </li>
                {% endfor %}
              </ul>
			</div>
		{% endif %}
		{% if block.type == 'search' %}
			<div class="blog_sidebar_item">
              {% if block.settings.title != blank %}
                  <h{{ settings.blog_sidebar_heading_tag }} class="sidebar_title">{{ block.settings.title }}</h{{ settings.blog_sidebar_heading_tag }}>
              {% endif %}
              <form class="blogSearch" action="/search">
                <input type="hidden" name="type" value="article" />
                
                <input type="text" name="q" class="search_box" placeholder="{% if block.settings.placeholder == blank %}{{ blog.title | escape }}...{% else %}{{ block.settings.placeholder }}{% endif %}" autocapitalize="off" autocomplete="off" autocorrect="off" value="{{ search.terms }}" />
                <button type="submit" class="blog_sidebar_search_btn"><i class="fa fa-search"></i></button>
              </form>
  			</div>
		{% endif %}
		{% if block.type == 'text' %}
			<div class="blog_sidebar_item">
              {% if block.settings.title != blank %}
                  <h{{ settings.blog_sidebar_heading_tag }} class="sidebar_title">{{ block.settings.title }}</h{{ settings.blog_sidebar_heading_tag }}>
              {% endif %}
              <div class="blog_sidebar_html">
                	{{ block.settings.text }}
              </div>

  			</div>
		{% endif %}
	{% endfor %}
{% endif %}


{% schema %}

{
  "name": "Blog Sidebar",
	"settings": [],
     
    "blocks": [
      {
        "type": "blog_tags",
        "name": "Blog post tags",
		 "limit": 1,
        "settings": [
          	{
              "type": "text",
              "id": "title",
              "label": "Title"
            }
          ]
        
      },

	  
      {
        "type": "menu",
        "name": "Menu",
        "settings": [
          {
            "type": "link_list",
            "id": "menu",
            "label": "Menu"
          }
        ]
      },
	  {
        "type": "image",
        "name": "Image",
        "settings": [
          {
            "type": "text",
            "id": "title",
            "label": "Title"
          },
          {
              "type": "image_picker",
              "id": "image",
              "label": "Image"
          }
        ]
      },
      {
        "type": "recent_posts",
        "name": "Recent blog posts",
        "limit": 1,
        "settings": [
		  {
            "type": "text",
            "id": "title",
            "label": "Title"
          },
          {
            "type": "range",
            "id": "blog_post_count",
            "label": "Posts to Show",
            "min": 0,
            "max": 20,
            "step": 1,
             "default": 5
          }

        ]
      },    
      {
        "type": "search",
        "name": "Search form",
        "limit": 1,
		"settings":[
			{
              "type": "text",
              "id": "title",
              "label": "Title"
            },
			{
              "type": "text",
              "id": "placeholder",
              "label": "Placeholder Text"
            }
		]
      },
      {
        "type": "text",
        "name": "Custom HTML",
        "settings": [
          {
            "type": "text",
            "id": "title",
            "label": "Title"
          },
          {
            "type": "richtext",
            "id": "text",
            "label": "Text"
          }
        ]
      }
    ]
}

{% endschema %}
