23.03.2013 Views

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

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Turning a design template into a Jinja2 template<br />

In a website, you'll often have the same basic layout <strong>and</strong> design for many of the<br />

pages, <strong>with</strong> differences in content <strong>and</strong> metadata. To turn the Minimalism design<br />

template into a Jinja2 template that you can use for multiple actual pages, figure out<br />

what is general to all the pages <strong>and</strong> what is specific to each one. Look at the head<br />

element from Minimalism:<br />

<br />

<br />

Minimalism - Home<br />

<br />

<br />

<br />

<br />

<br />

In this case, pretty much everything but the title is shared across pages, So I'll turn<br />

just the title content into a template field from metadata:<br />

{{ resource.meta.title }}<br />

The head element also links to icons, styles, <strong>and</strong> other resources. <strong>Hyde</strong> manages the<br />

correspondence between the folders for such resources <strong>and</strong> their URLs in resulting<br />

pages, so you have to update these links to use a special <strong>Hyde</strong> function:<br />

<br />

...<br />

<br />

You can place the favicon.gif file inline during development. When you launch a site<br />

into production, it's best to locate the icon image at the root of the domain, <strong>and</strong> the<br />

explicit links become superfluous.<br />

You also need to update any images or links to JavaScript files or other resources,<br />

using the same pattern as in previous examples. For example, one feature image<br />

used to show off the template looks like this after update:<br />

<br />

<br />

At this point, <strong>Hyde</strong> can display the template just as it looks on the demo site from<br />

which you downloaded it. But your work is not entirely done. Now you have to set up<br />

to replace the "Lorem Ipsum" dummy text <strong>with</strong> useful content.<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 5 of 9

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

Saved successfully!

Ooh no, something went wrong!