<!--This is an RML template to produce birthday cards from a database.-->
{{def(friend)}}
<!-- The line above is used by the preppy templating system to give-->
<!-- you access to the 'friend' variable passed through from the   -->
<!-- calling python script                                         -->
<!DOCTYPE document SYSTEM "rml.dtd">
<!-- The filename below isn't used - instead the filename -->
<!-- is created dynamically inside 'rldb.py'             -->
<document filename="rldb.pdf">
    <template pageSize="400,600">
        <pageTemplate id="main">
            <pageGraphics>
                <!--Create some static text which appears on-->
                <!--every page in the same place            -->
                <setFont name="Helvetica-Bold" size="20"/>
                <fill color="red"/>
                <drawString x="110" y="450">HAPPY BIRTHDAY!</drawString>
            </pageGraphics>
            <!--Now define a frame to contain text from the <story> section  -->
            <!--below. To make the frames visible, add 'showBoundary="1"' to -->
            <!--the <template> tag above.                                    -->
            <frame id="first" x1="0" y1="200" width="400" height="200"/>
        </pageTemplate>
    </template>
    <stylesheet>
        <!--Define a basic text style-->
        <paraStyle name="textstyle1" fontName="Helvetica" fontSize="16"
                   leading="16" spaceBefore="16" alignment="center"/>
    </stylesheet>
    <!--Content in the <story> section 'flows' into the -->
    <!--frames defined in the <pageTemplate> section above-->
    <story>
        <!-- Create the dynamic text using the variable 'friend' passed -->
        <!-- in at the top of the document                              -->
        <para style="textstyle1">
            Hi {{friend.firstName}},
        </para>
        <para style="textstyle1">
            It's your birthday!
        </para>
        <!-- This demonstrates how to use python code directly inside  -->
        <!-- your rml template. 'age' will be a python timedelta object-->
        <!-- containing the number of days since birthday.             -->
        <!-- Anything inside script/endscript or double curly          -->
        <!-- braces gets interpreted directly by Python, via preppy.   -->
        {{script}}
            import datetime
            today=datetime.date.today()
            age = today - friend.DOB
        {{endscript}}
        <para style="textstyle1">
            <!--rough calculation to account for leap years, -->
            <!--formatted to the nearest integer             -->
            You are {{('%.i' % (age.days/365.2425))}} years old!
        </para>
        <para style="textstyle1">
            All the best, from ReportLab
        </para>
    </story>
</document>
    