HOWTO: How to Include Images in Your Stories

mikeraynham edited this page May 17, 2011 · 2 revisions
Clone this wiki locally


In Bricolage 1.6 or later, using a structure like the following:

<div class="list">

Use the following code to include images in your stories:

% # Only show this if we are on the first page
% unless ($burner->get_page) {
    <h1><% $story->get_title %></h1>
    <% $element->get_data("deck") %>
    <hr size="1" noshade />
% }

%# Display all the pages of this story
% $burner->display_pages("page");

<hr size="1" noshade />
% if (my $prev = $burner->prev_page_file) {
    <a href="<% $prev %>">Previous Page</a>
% }

% if (my $next = $burner->next_page_file) {
    <a href="<% $next %>">Next Page</a>
% }

foreach my $e ($element->get_elements) {
    if ($e->has_name("related_media")) {
    } elsif ($e->has_name("paragraph")) {
        $m->out("<p>" . $e->get_data ."</p>\n");

%  my $rel_media = $element->get_related_media;
<img src="<% $rel_media->get_uri %>" align="right" />


You can add as many Related Media subelements as you like, then order their position on the page using the ordering tools in the UI. I wanted to use an image that is right-aligned on the page, then, on certain occasions, another image, in the same story, that is left aligned.

Disclaimer: I don’t know if the following is the best way to do this, but it works.

I created an element called Left Image of type Related Media. Then I added it as a sub-element of The template for Left Image, called, looks exactly like the template, except the align in the image tag is align="left".

This allows you to use multiple images in your stories, and have the layout be a bit more aesthetically pleasing.

That’s it, this allows you to handle images in your stories.