Last active
December 23, 2015 13:19
-
-
Save hyperking/6640960 to your computer and use it in GitHub Desktop.
Jinja2 Key Value Spliter for Pelican meta data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# What I am attempting to do is split each key value pair groups down into smaller key value pairs spliting each at specified characters i.e:("=" "," ":" "|" )..etc. the characters used are arbitrary | |
# Example: Markdown metadata looks like this. | |
Title: Demo Product | |
date: 9-19-2013 | |
productvariations: Sizes=Small:13.00,Med:33.00,Large:42.00|Colors=Red,Green,Blue | |
# We need to output the following as: | |
Sizes: | |
Small 13.00 | |
Med 33.00 | |
Large 42.00 | |
Colors: | |
Red | |
Green | |
Blue | |
# My current solution using jinja is this: | |
{% for variations_groups in article.productvariations.split('|') %} | |
{% set variation_name = loop.cycle(variations_groups.split('=')) %} | |
<h2>{{variation_name}}:</h2> | |
<ul> | |
{% for variation_items in article.productvariations.split(',') %} | |
{% set pairlist = loop.cycle(variation_items.split(':')) %} | |
<li> {{pairlist[0]}} {{pairlist[1]}} </li> | |
{% endfor %} | |
</ul> | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@hyperking check this https://gist.github.com/talha131/6642404