Using Custom Attributes in Blog YAML Header

59 views
Skip to first unread message

Chee How Chua

unread,
May 18, 2014, 12:38:45 PM5/18/14
to blogofil...@googlegroups.com
Hi,

First of all, a big thank-you to this wonderful project.

I have a question about putting custom attributes into the YAML header for posts.

I would like to add a "showcase" attribute to header like so:

---
categories: General Stuff
date: 2010/06/29 15:25:00
title: Filler post 1
showcase: "An image URL"
---

I want to then use it in a post excerpt (post_excerpt.mako).

I've enabled the excerpt flag and the excerpt function is working.

I want to use the "showcase" attribute as an image source for SOME of the posts, not all of them.

My post_excerpt.mako is as follows:

<%inherit file="post.mako" />
<%def name="post_prose(post)">
  ${post.excerpt}
</%def>

I tried this:

<%inherit file="post.mako" />
<%def name="post_prose(post)">
% if excerpt in post:
        ${post.excerpt}
% else:
        ${post.content}
$ endif
</%def>

but it is giving me an error that finally ends in:

mako.exceptions.SyntaxException: Unterminated control keyword: 'if' in file '_templates/blog/post_excerpt.mako' at line: 3 char: 1

I'm not very fluent with Python nor Mako but I do understand the basic syntax,

Any pointer in the right direction will be tremendously helpful.

Thanks!

CCH

Doug Latornell

unread,
May 18, 2014, 8:16:20 PM5/18/14
to blogofil...@googlegroups.com, Chee How Chua
I'm not sure if it's just a copy/paste error in your message, but the if block above should be ended with %endif, not $endif.

but it is giving me an error that finally ends in:

mako.exceptions.SyntaxException: Unterminated control keyword: 'if' in file '_templates/blog/post_excerpt.mako' at line: 3 char: 1

I'm not very fluent with Python nor Mako but I do understand the basic syntax,

Any pointer in the right direction will be tremendously helpful.

Thanks!

CCH

--
You received this message because you are subscribed to the Google Groups "blogofile-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blogofile-disc...@googlegroups.com.
To post to this group, send email to blogofil...@googlegroups.com.
Visit this group at http://groups.google.com/group/blogofile-discuss.
For more options, visit https://groups.google.com/d/optout.

Chee How Chua

unread,
May 19, 2014, 6:47:22 AM5/19/14
to blogofil...@googlegroups.com
Doh! I can't believe I'm still making this kind of mistake...

Thanks Doug!

I can now use the following to check for the presence of an additional attribute to display, or if that is not available, display the excerpt if it is not empty or the actual contents.

<%inherit file="post.mako" />
<%def name="post_prose(post)">
% if hasattr(post, 'showcase'):
    ${post.showcase}
% elif len(post.excerpt) > 0:
    ${post.excerpt}
% else:
    ${post.content}
% endif
</%def>
Reply all
Reply to author
Forward
0 new messages