hdra / pelican-cait

Theme for Pelican static site generator. Badly designed.
MIT License
47 stars 26 forks source link

Trying to create a "categories" page, with no result displayed #9

Closed Kentoseth closed 10 years ago

Kentoseth commented 10 years ago

Hello,

I am trying to create a categories.html page in the /templates/ directory, but when generating output for that template, I get no categories displayed.

Here is the code:

{% extends "base.html" %}
{% block title %}
{{ SITENAME }} - Categories 
{% endblock %}

{% block stylesheets %}
    {{ super() }}
    <link rel="stylesheet" href="{{ SITEURL }}/theme/css/blog.css">
    <link rel="stylesheet" href="{{ SITEURL }}/theme/css/github.css">
{% endblock stylesheets %}

{% block content %}
{% include "sidebar.html" %}

<div id="post-container">
        <ol id="post-list">
            <li>
                {% for category in categories %}
                <div class="post-entry">
                    <header class="entry-header">
                        <a href="{{ SITEURL }}/{{ category.url }}"><h4>{{ category.title }}</h4></a>
                    </header>
                    <hr/>
                </div>
                {% endfor %}
            </li>
        </ol>
</div>

{% endblock content %}

I have tried multiple varieties to display the categories, including a simple:

<div>
   {for category in categories}
   <div>{{ category }}</div>
</div>

However, nothing has worked so far. I suspect that it has something to do with how categories are generated. Any help will be appreciated.

The goal is to display all the categories on the same blog layout where articles appear (meaning sidebar on the left and a list of categories on the right).

hdra commented 10 years ago

I can't tell for sure without seeing the rest of the code. You can read more on developing a theme for Pelican here: http://docs.getpelican.com/en/3.3.0/themes.html

Also, if you need any help with a general problem with Pelican, #pelican on Freenode is great place to get help.

Kentoseth commented 10 years ago

Hello @hdra , I am using the Cait theme you have developed. All the other code is the same, I am simply adding a "categories.html" file to the /templates/ folder.

How do you call upon categories to display on their own using your theme?

Kentoseth commented 10 years ago

Okay I got it to work now, using the same styling as the index.html page. It seems that the categories will show using the normal code, but it has to be placed in an HTML tag using the - class="post-container"- otherwise it will be there, but not be seen (I assume it is on the left side of the page, hiding under the sidebar).

If you'd like to see my code, I can paste it here. Let me know.

Thanks for the help :-)

hdra commented 10 years ago

I assume you got it to work? One way to debug when developing a theme is by checking the HTML source generated instead of checking it visually on the browser. This way, you would know if the issue is with the generator, or just a mistake in styling.

Kentoseth commented 10 years ago

Yeah, it's working.

I ended up doing that (checking the output files) to make sure that the correct output is being generated.

I am using the same styling for entry headers on each category and it looks quite nice. Here is the code for categories.html:

{% extends "base.html" %}
{% block title %}
{{ SITENAME }} - Categories 
{% endblock %}

{% block stylesheets %}
    {{ super() }}
    <link rel="stylesheet" href="{{ SITEURL }}/theme/css/blog.css">
    <link rel="stylesheet" href="{{ SITEURL }}/theme/css/github.css">
{% endblock stylesheets %}

{% block content %}
{% include "sidebar.html" %}

<div id="post-container">
        <ul class="entry-header">
        {% for category, articles in categories %}
            <h2><li><a href="{{ SITEURL }}/{{ category.url }}">{{ category }}</a></li></h2>
        {% endfor %}
        </ul>
</div>

{% endblock content %}