Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some themes using "loop" throw a critical error when creating the blog #481

Closed
MrMovl opened this issue Jan 23, 2017 · 7 comments
Closed

Comments

@MrMovl
Copy link

MrMovl commented Jan 23, 2017

Hi there, this one is kind of strange. A lot of themes are broken for me, in fact, every theme which uses "loop" somewhere in any template. Even in 4 year old themes. I am not sure if I have a strange setup, but I don't think so.

Basically, if I add the following line to my pelicanconf.py
THEME = "/home/me/workspace/pelican-themes/nmnlist"
and then run the build with make html I get the following error:
CRITICAL: UndefinedError: 'loop' is undefined
Makefile:65: recipe for target 'html' failed
make: *** [html] Error 1

I also get that error when building manually using
pelican content -o output -s pelicanconf.py

Maybe this has a simple solution, but I was not able to find anything.

The project I used here is not much more then what pelican quickstart generates, except two about me articles (in two languages).

Let me know if any additional info is necessary.

@justinmayer
Copy link
Member

Hi Tomke. As mentioned in the Getting Help section of the docs, please test with the default "notmyidea" theme. Assuming you don't see the error with that theme, try comparing that theme's source to ones where you get the error and see if you can determine the difference that's causing the problem. Thanks for helping to track this down!

@MrMovl MrMovl changed the title All themes using "loop" throw a critical error when creating the blog Some themes using "loop" throw a critical error when creating the blog Jan 24, 2017
@MrMovl
Copy link
Author

MrMovl commented Jan 24, 2017

Sure, sorry, should have thought of including that info.

I can use the notmyidea theme from the pelican repo as well as several others from this repo (working examples are bootstrap2-dark, Flex and Medius).

I first thought all themes containing the loop keyword did not work (like line 8 here). But I just saw that the notmyidea theme from the pelican repo also uses loop. But maybe all themes from this repo using loop are broken. I haven't had the time to test them all, but testing a few seemed to confirm that suspicion.

My python is a little rusty, so I wonder where loop comes from in the template mentioned above. But I went ahead and removed all loop instances from the nmnlist theme (index.html and base.html), the resulting files are in this little gist.
With these changes the theme compiles.

I first suspected some problem with wrong python versions, but I tested this on Manjaro Linux, Linux Mint and an Ubuntu Server.

Letme know what else you need.

@piorekf
Copy link

piorekf commented Feb 22, 2017

@MrMovl The error is not because of line 8 in that file but rather line 28. It tries to use loop variable outside of for loop. loop variable comes from inside of Jinja2 engine.

Proper fix instead of removing every occurrence of loop variable can look like this:

@@ -23,11 +23,11 @@
         {% else %} 
             <li><a href="{{ SITEURL }}/{{ article.url }}" rel="bookmark" title="Permalink to {{ article.title}}">{{ article.title }}</a></li>
         {% endif %}
-{% endfor %}
-    {% if loop.length > 1 %}
-    </ol>
-    </section><!-- #article-list -->
-{% endif %}
+        {% if loop.last %}
+        </ol>
+        </section><!-- #article-list -->
+        {% endif %}
+    {% endfor %}
 {% else %}
     No posts found.
 {% endif %}

@justinmayer
Copy link
Member

Thanks for the helpful tip, Piotrek. Much appreciated!

@kmannarbor
Copy link

Hi, I'm having a similar problem. When I try to use pelican-bootstrap3, it returns the following error:

CRITICAL: UndefinedError: '_' is undefined
make: *** [Makefile:44: html] Error 1

I have tested the default (notmyidea) theme and it works great. Also, like MrMovl, bootstrap2-dark and medius work just fine as well. I'm not sure if the code you posted would work in my situation and I'm unsure where to copy that code. Any help would be greatly appreciated!

@justinmayer
Copy link
Member

@kmannarbor: make is simply an automation wrapper around the core pelican command. As such, I recommend using pelican commands whenever debugging.

@avaris
Copy link
Member

avaris commented Jun 26, 2019

@kmannarbor probably related to #460

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants