velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Logue, Mitchel G" <>
Subject #parse variables not passed to #include(ed) files
Date Wed, 19 Jan 2011 20:56:32 GMT
I am using Velocity to help create documents using Mavens APT and for
the most part it is working great.  But, I am having a problem when I
attempt to use #parse to set a variable that I want to be able to use
throughout the document, including #includ(ed) documents.  Here's the


I have multiple files that are used within multiple other documents, so
I #include these "Common" documents within other documents.  I do this
as follows:


1.	I create a file (for this example we'll call it myDoc.apt.vm)
and within this document I have a line (or lines that look like the


#include ( "..\..\..\myDoc2\Chapter7\" )


This works great, until I have a #include(ed) file that contains an
image and both files (the original and the one that wants to include it)
are at different directory levels.  For instance:


1. exists in


2.	The above file is #includ(ed) in a file that exists in


3. contains an image whose path is given as a
relative path as in ..\..\..\CommonImage1.jpg.


4.	When the file from number 2 above #include(s) the file Mavens APT tries to find the image but it can't
because ..\..\..\ puts it one directory too deep in the tree.


Here's the directory layout because it's difficult to see the problem
without a diagram:


- src

  - - site

    - - - apt

      - - - - myDoc1

         - - - - - Chapter1

           - - - - - - myDoc.apt.vm

           - - - - - -

      - - - - myDoc2

         - - - - - Chapter7

            - - - - - - Overview

              - - - - - - overview.apt.vm

  - - resources

    - - - images

      - - - - commonImage1.jpg

      - - - - someImage.jpg



  So, what I want to do is set a variable in each of the .apt.vm files
called $pathToImages (or something of that nature) and set that variable
to the correct path.  But, the #includ(ed) file knows nothing of the
variable $pathToImages.  I am guessing this is true because the file is
"Included" before the #set is executed.  And, I say that because inside
the apt.vm file that contains the #set it knows about the variable, but
when I look at the variable in the included file, which is included
within the apt.vm file, it doesn't know about the variable.  Here's an


File:  myDoc.apt.vm


#set $pathToImages = "../../../images"


  pathToImages = $pathToImages


#include ( "" )







* Overview


  * This is an overview


  Some overview text




  pathToImages = $pathToImages



In the above example, the document created for "myDoc" looks like this,
I have added line numbers to discuss each line:


1.  pathToImages = ../../../images


2.  Overview


3.    This is an overview


4.    Some overview text


5.   [x] 


6.   [commonImage1.jpg image]  


7.  pathToImages = $pathToImages




Line      Comment


1.                   Shows that $pathToImages is set, as expected

2-4               Normal document rendering from Maven (Difficult to
show correct formatting, but it isn't important)

5          A broken image because it can't find the specified image

6          The expected image is displayed

7          Shows that the variable $pathToImages is no set



So, does anyone know how I can make this work?  And, I know I could just
place the images within the "Calling" file, but that kind of defeats the
purpose of including the file in another file.  I also could always make
sure that all files that will be "Including" other files sit at the same
level in the directory tree, but that isn't really a solution.  So,
wondering if someone on this list is more proficient in Velocity and can
help me out.


And, let me apologize up front if this has been addressed in a previous
thread, I looked through the posts for more than a year back and didn't
see it.



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message