Build rapid and lightweight static websites with Hyde - IBM

Build rapid and lightweight static websites with Hyde - IBM Build rapid and lightweight static websites with Hyde - IBM

23.03.2013 Views

developerWorks® ibm.com/developerWorks/ Filling in content You can easily to mark places in the template where you want to fill in pagespecific markup. Just add Jinja block markers. Listing 3 illustrates in a section from minimalism.j2 . Listing 3. Section of the "Minimalism" template illustrating Jinja block markers {% block intro %} "Simplicity is the ultimate sophistication" - Leonardo da Vinci Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec molestie. Sed aliquam sem ut arcu. Phasellus sollicitudin. Vestibulum condimentum facilisis nulla. In hac habitasse platea dictumst. Nulla nonummy. Cras quis libero. {% endblock intro %} I added {% block intro %} and {% endblock intro %} to the template HTML. As you can see, I left the dummy text in place. This is fine because I will override it page by page. Listing 4 is sample page, saved as index.html, which is based on the minimalism.j2 template but overrides two template blocks. Listing 4. Example page based on Listing 3, but overriding two Jinja template blocks, using HTML --- extends: minimalism.j2 title: Strange Case of Dr Jekyll and Mr Hyde description: Tribute to a Victorian classic -- {% block intro %} Strange Case of Dr Jekyll and Mr Hyde —R.L. Stevenson "I knew myself, at the first breath of this new life, to be more wicked, tenfold more wicked, sold a slave to my original evil; and the thought, in that moment, braced and delighted me like wine." {% endblock intro %} {% block group1 %} The author Robert Louis Balfour Stevenson (13 November 1850 – 3 December 1894) was a Scottish novelist, poet, essayist and travel writer. His best known books include Treasure Island, Kidnapped, and Strange Case of Dr Jekyll and Mr Hyde. Read more {% endblock group1 %} Build rapid and lightweight static websites with Hyde Page 6 of 9

ibm.com/developerWorks/ developerWorks® Listing 5 illustrates the use of Markdown to express part of a page's content, using the {% filter markdown -%} instruction to invoke Hyde's built-in markdown converter. Listing 5. Example page based on Listing 3, but overriding two Jinja template blocks, using Markdown --- extends: minimalism.j2 title: Strange Case of Dr Jekyll and Mr Hyde description: Tribute to a Victorian classic --- {% block intro %} {% filter markdown -%} # *Strange Case of Dr Jekyll and Mr Hyde* ## "I knew myself, at the first breath of this new life, to be more wicked..." {%- endfilter %} {% endblock intro %} {% block group1 %} {% filter markdown -%} ### The author **Robert Louis Balfour Stevenson** (13 November 1850 – 3 December 1894) was a Scottish novelist, poet, essayist and travel writer. His best-known books include *Treasure Island*, *Kidnapped*, and *Strange Case of Dr Jekyll and Mr Hyde* {%- endfilter %} Read more {% endblock group1 %} Only the content within the filter instructions are interpreted as markdown. Notice how those bits are flush left, unlike the HTML bits, which are indented according to block elements. This is because indentation is significant in Markdown and not in HTML. Summary I only scratched the surface of the features available in Jinja templates and other components of Hyde. That works fine because Hyde is designed so that you can begin with the simpler functions and work up to more sophisticated features as you go along, whenever you need to enhance automation and workflow. You can develop many simple web pages with simple blocks (which you can nest). If you need automatically compiled weblogs and the like, Hyde's default layout provides a good example. Overall, Hyde gives you most of the features of content management systems and low-level web publishing frameworks. With the file system as the backing store, very little of your system is obscured or mysterious. I think this is a great benefit, and you now have enough of the basics to get started and create a simple web page with Hyde, and a web design template of your choosing. Build rapid and lightweight static websites with Hyde Page 7 of 9

developerWorks® ibm.com/developerWorks/<br />

Filling in content<br />

You can easily to mark places in the template where you want to fill in pagespecific<br />

markup. Just add Jinja block markers. Listing 3 illustrates in a section from<br />

minimalism.j2 .<br />

Listing 3. Section of the "Minimalism" template illustrating Jinja block markers<br />

<br />

{% block intro %}<br />

<br />

<br />

"Simplicity is the ultimate sophistication"<br />

- Leonardo da Vinci<br />

<br />

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.<br />

Donec molestie. Sed aliquam sem ut arcu. Phasellus sollicitudin.<br />

Vestibulum condimentum facilisis nulla. In hac habitasse platea<br />

dictumst. Nulla nonummy. Cras quis libero.<br />

<br />

<br />

{% endblock intro %}<br />

I added {% block intro %} <strong>and</strong> {% endblock intro %} to the template HTML. As<br />

you can see, I left the dummy text in place. This is fine because I will override it<br />

page by page. Listing 4 is sample page, saved as index.html, which is based on the<br />

minimalism.j2 template but overrides two template blocks.<br />

Listing 4. Example page based on Listing 3, but overriding two Jinja template<br />

blocks, using HTML<br />

--- extends: minimalism.j2<br />

title: Strange Case of Dr Jekyll <strong>and</strong> Mr <strong>Hyde</strong><br />

description: Tribute to a Victorian classic --<br />

{% block intro %}<br />

<br />

<br />

Strange Case of Dr Jekyll <strong>and</strong> Mr <strong>Hyde</strong><br />

—R.L. Stevenson<br />

"I knew myself, at the first breath of this new life,<br />

to be more wicked, tenfold more wicked, sold a slave to my original evil;<br />

<strong>and</strong> the thought, in that moment, braced <strong>and</strong> delighted me like wine."<br />

<br />

<br />

{% endblock intro %}<br />

{% block group1 %}<br />

<br />

The author<br />

Robert Louis Balfour Stevenson (13 November 1850 – 3 December 1894)<br />

was a Scottish novelist, poet, essayist <strong>and</strong> travel writer. His best known<br />

books include Treasure Isl<strong>and</strong>, Kidnapped, <strong>and</strong><br />

Strange Case of Dr Jekyll <strong>and</strong> Mr <strong>Hyde</strong>.<br />

<br />

<br />

Read more<br />

<br />

{% endblock group1 %}<br />

<strong>Build</strong> <strong>rapid</strong> <strong>and</strong> <strong>lightweight</strong> <strong>static</strong> <strong>websites</strong> <strong>with</strong> <strong>Hyde</strong> Page 6 of 9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!