Export Part of a Page
Steps
An export displays the page through the same pipeline a view does, so the page's scripts run again while it is being exported, and they can tell the two apart: the export job carries over the action of the request that started it, and that action is latexexport. Testing it in a Velocity script keeps a part of the page out of the LaTeX package while leaving it on the page, which is how a LaTeX export drops the navigation aids a reader of the PDF does not need. This How-to removes a table of contents from the export.
- Export the page as it stands and open its file under pages/ in the package. Everything the page displays is in there, the table of contents included, where it becomes an etoc block repeating what the PDF's own table of contents already gives.
\begin{document} \etocsettocstyle{}{} \tableofcontents \heading{1}{Introduction} \label{HIntroduction} Some text. - Wrap the part to leave out in a Velocity macro and guard it with the action. The page needs the Script right for the macro to run at all.
{{velocity}} #if ($xcontext.action != 'latexexport') {{toc/}} #end {{/velocity}} = Introduction = Some text.The guard is a plain Velocity if, so anything the page can compute is available to it: a whole section, one table row, an image swapped for another. What it must not hold is content you want in both outputs, since the export never takes the else branch either.
- Export again. The guarded block is gone from the package and nothing is left where it stood, while viewing the page still shows the table of contents, because $xcontext.action is view there.
\begin{document} \heading{1}{Introduction} \label{HIntroduction} Some text.
FAQ
Does this work for a PDF export as well?
Yes. Both export entries go through the same latexexport action, so one guard covers them. To treat them differently, read the pdf request parameter, which the PDF entry sets to true and the LaTeX one leaves unset.
Can I add something only to the export?
Test the action the other way round, with == instead of !=. To add the same thing to every exported page rather than to one page, use an extension point instead.
My script sees neither the action nor the request parameters
The export runs as a background job, which does not inherit the servlet request; the exporter copies the action and the request parameters into the job on purpose. What it does not copy is whatever the page that triggered the export left in the execution context.