36 lines
1.8 KiB
XML
Executable File
36 lines
1.8 KiB
XML
Executable File
<chapter id="ljp.bml.core">
|
|
<chapterinfo>
|
|
<title>Core <abbrev>BML</abbrev> blocks</title>
|
|
</chapterinfo>
|
|
<title>Core <abbrev>BML</abbrev> blocks</title>
|
|
<para>
|
|
Core blocks are predefined blocks that are named with a leading underscore.
|
|
Most core blocks have a higher purpose than simple template use:
|
|
</para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><literal role="core.bml.block">_code</literal></term>
|
|
<listitem><para>
|
|
<literal><?_code _code?></literal> blocks are perhaps the most useful feature of
|
|
<abbrev>BML</abbrev> outside of the ability to have global site templates.
|
|
These blocks allow template authors to embed pieces of executable Perl code
|
|
within the bml page that get executed on the server.
|
|
</para><para>
|
|
</para><para>
|
|
The code you write gets executed in its own package (namespace) called
|
|
<computeroutput>BMLCodeBlock::</computeroutput>.
|
|
Any variables you declare in one code block on a page without using
|
|
<literal>my</literal> are carried on to the next <literal>_code</literal> block.
|
|
</para><para>
|
|
Because the BML parser must evaluate everything on the page before sending the
|
|
<abbrev>HTTP</abbrev> headers, make sure you don't print anything.
|
|
Any output printed to <literal>STDOUT</literal> will just be interpreted as
|
|
<abbrev>HTTP</abbrev> headers. How the <literal>_code</literal> blocks work is
|
|
that you need to return a value at the end.
|
|
Whatever value your code fragment returns is what the block evaluates to.
|
|
Usually what you end up doing is building a string, concatenating things to it
|
|
over and over, and then returning it at the end.
|
|
</para></listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</chapter> |