You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Logue, Mitchel G" <mi...@verizonbusiness.com> on 2011/01/19 21:56:32 UTC

#parse variables not passed to #include(ed) files

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
scenario:

 

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
following)

 

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

 

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.	SomeCommonFile.inc exists in
src\site\apt\myDoc1\Chapter1\myCommonFile.inc

 

2.	The above file is #includ(ed) in a file that exists in
src\site\apt\myDoc2\Chapter7\Overview

 

3.	SomeCommonFile.inc 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
SomeCommonFile.inc 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

           - - - - - - SomeCommonFile.inc

      - - - - 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
example:

 

File:  myDoc.apt.vm

 

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

 

  pathToImages = $pathToImages

 

#include ( "SomeCommonFile.inc" )

 

[$pathToImages/someImage.jpg]

 

 

File:  SomeCommonFile.inc

 

* Overview

 

  * This is an overview

 

  Some overview text

 

[$pathToImages/commonImage1.jpg]

 

  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.

 

 


RE: #parse variables not passed to #include(ed) files

Posted by "Logue, Mitchel G" <mi...@verizonbusiness.com>.
Barbara,

Thank you so much for your quick response.

And, I'm sorry but it seems no matter how hard I try to be accurate in
creating the question I forget something.  The line in File myDoc.apt.vm
is set just as you say to set it (well except the Velocity docs all show
the #set command with spaces after the open and before the close
parenthesis, so in my document it actually looks like this):

#set( $imagePath = "../../../images" )

But, I know the #set works because as you can see in line 1 of the
generated output, the variable is correctly set, and when it uses the
variable to get the image commonImage1.jpg on line 6, it correctly finds
and displays the image.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: #parse variables not passed to #include(ed) files

Posted by Barbara Baughman <ba...@utdallas.edu>.
Try

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

Barbara Baughman
Systems Analyst
X2157

On 01/19/11 14:56, Logue, Mitchel G wrote:
> 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
> scenario:
>
>
>
> 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
> following)
>
>
>
> #include ( "..\..\..\myDoc2\Chapter7\someCommonFile.inc" )
>
>
>
> 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.	SomeCommonFile.inc exists in
> src\site\apt\myDoc1\Chapter1\myCommonFile.inc
>
>
>
> 2.	The above file is #includ(ed) in a file that exists in
> src\site\apt\myDoc2\Chapter7\Overview
>
>
>
> 3.	SomeCommonFile.inc 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
> SomeCommonFile.inc 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
>
>             - - - - - - SomeCommonFile.inc
>
>        - - - - 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
> example:
>
>
>
> File:  myDoc.apt.vm
>
>
>
> #set $pathToImages = "../../../images"
>
>
>
>    pathToImages = $pathToImages
>
>
>
> #include ( "SomeCommonFile.inc" )
>
>
>
> [$pathToImages/someImage.jpg]
>
>
>
>
>
> File:  SomeCommonFile.inc
>
>
>
> * Overview
>
>
>
>    * This is an overview
>
>
>
>    Some overview text
>
>
>
> [$pathToImages/commonImage1.jpg]
>
>
>
>    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.
>
>
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org