Using the Falcon template document within a Falcon script

27 views
Skip to first unread message

Roberto Giacomelli

unread,
Jan 18, 2013, 3:01:11 AM1/18/13
to falc...@googlegroups.com
Hello,
I'm interesting on the Falcon Template Document from a database reporting point of view.
I  wrote an example of a .ftd files that produces a LaTeX source:
[code]
% a very simple example...
\documentclass{<? print(classname()) ?>}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\begin{document}
Hello World!
\end{document}
<?
function classname()
    return "article"
end
?>
[/code]

The compilation of this code prints text on the standard output.
How I can call this template from a separate Falcon script and retrieve the template's result in a string to save it on an external disk file?
Please, use "simpleTeX.ftd" as the name of the Falcon template in your answers.
Thank you.
Robitex

Giancarlo Niccolai

unread,
Jan 18, 2013, 9:35:59 AM1/18/13
to falc...@googlegroups.com
Il 18/01/2013 09:01, Roberto Giacomelli ha scritto:
> Hello,
> I'm interesting on the Falcon Template Document from a database
> reporting point of view.
> I wrote an example of a .ftd files that produces a LaTeX source:
> [code]
> % a very simple example...
> \documentclass{<? print(classname()) ?>}
> \usepackage[T1]{fontenc}
> \usepackage[utf8]{inputenc}
>
> \begin{document}
> Hello World!
> \end{document}
> <?
> function classname()
> return "article"
> end
> ?>
> [/code]
>

1) use the compiler module to load the module.
2) redirect output to a stringstream this way:

ss = StringStream()
out = stdOut(ss)

(out is the old standard stream)

3) invoke the main function of the loaded module.

4) ss.closeToString() should give you the output.

5) remember to stdOut(old)

The include() function is usually a viable shortcut for using the
compiler module.

For an extensive use of this technique see the nest.fal file in
frameworks/nest

Gian.

Reply all
Reply to author
Forward
0 new messages