Skip to content

Content Flows

By default, content included within a page definition will be included every time that page is used. However, we don't always want this to the case. For example, if we're writing an article we'd like each page to show a specific amount of content, and page break when we run out of space on the current page. We then want to following page to pick up where the last page left off.

e.g.

xml
<!-- The First Page -->
<p>
    This is the first paragraph. Lorem ipsum...
</p>


...

<!-- The Second Page -->
<p>
    This is another paragraph. Lorem ipsum...
</p>

To do this, let's create and reference a flow called body:

xml
<press>
    <flows>
        <body>
            <p>This is the first paragraph. Lorem ipsum...</p>

            ...

            <p>This is another paragraph. Lorem ipsum...</p>
        </body>
    </flows>

    <document>
        <page format="a4" page-margin="2cm">
            <flow name="body" />
        </page>
    </document>
</press>

Here, we've defined the "body" flow. You can define any number of content flows. We can read content from the body flow to a page definition using a <flow name="..." /> tag. Each time content is taken from a flow, it resume from the last place it left off.

We'd like to be able to to write the body flow's contents onto as many pages as is necessary. This isn't what the above payload does. It would just create a single page with as much of the <flow>'s contents as it could fit.

If we want to display the entirety of the <flow> then we'll have to read from it again, after the first page runs out of space. The simplest way to do this is with a page repeat:

xml
<press>
    <flows>
        <body>
            <p>This is the first paragraph. Lorem ipsum...</p>

            ...

            <p>This is another paragraph. Lorem ipsum...</p>
        </body>
    </flows>

    <document>
        <page format="a4" page-margin="2cm" repeat="true" flow="body">
            <flow name="body" />
        </page>
    </document>
</press>

In the page definition we've set the attributes repeat="true" flow="body". The first (repeat="true") specifies that this page definition should repeat, and the second (flow="body") specifies that it should repeat over the "body" flow. This new page definition will do what we want, displaying the entirety of the flow's contents and page-breaking where necessary.

Defining flows within pages

For ease of use, flows which are only used within a single page can be defined within the page definition, like so:

xml
<page format="a4" page-margin="2cm" repeat="true" flow="body">
    <flow name="body">
        <p>This is the first paragraph. Lorem ipsum...</p>

        ...

        <p>This is another paragraph. Lorem ipsum...</p>
    </flow>
</page>

Flow names must be unique, so be careful not to re-use flow names. If two flows defined on the same page share a name, or if you try to re-use the name of a flow defined in the document's global <flows> tag, you'll get an error.

Static Content

Content outside of <flow> tags will always be included every time the page definition is used, for example if we defined our page as:

xml
<page format="a4" page-margin="2cm" repeat="true" flow="body">
    <p>My Report</p>
    <flow name="body">
        <p>This is the first paragraph. Lorem ipsum...</p>

        ...

        <p>This is another paragraph. Lorem ipsum...</p>
    </flow>
</page>

then every page would start with the paragraph "My Report" before continuing from where the previous page left off in the "body" flow.