Results 1 to 2 of 2
  1. #1
    txa
    txa is offline Member
    Join Date
    Feb 2017
    Posts
    1
    Rep Power
    0

    Default include a template into an other

    hi,


    I'm trying to include a template into an other template and to execute it i.e. to replace the variables.
    I'm doing it with #includeInContext("templates/includeMe.vm"),

    but the variable in the template, that is included, is doesn't replaced.

    Can anyone help?



    Java Code:
    VelocityEngine ve = new VelocityEngine();
    ve.init();
    
    	    
    Template t = ve.getTemplate(tempPath);
    VelocityContext context = new VelocityContext();
    StringWriter writer = new StringWriter();
    context.put("name", "Peter");
    t.merge(context, writer);
    	    
    System.out.println(writer.toString() );

    Java Code:
    This is the first template.
    Hello $name! Welcome to Velocity!
    
    #include("templates/includeMe.vm")
    Java Code:
    This template is included in the first template.
    Hello $name! Welcome to Velocity Template!
    printed:

    This is the first template.
    Hello Peter! Welcome to Velocity!

    This template is included in the first template.
    Hello $name! Welcome to Velocity Template!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: include a template into an other

    #include doesn't do any parsing. It's for including static chunks of text (eg some static footer maybe).
    You want to use (I think) #parse.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 01-11-2016, 03:21 PM
  2. Include images in a velocity template
    By claireimg in forum Apache Velocity
    Replies: 0
    Last Post: 03-18-2013, 11:18 AM
  3. Replies: 0
    Last Post: 03-02-2010, 08:28 AM
  4. include-prelude/include-coda
    By devin in forum Java Servlet
    Replies: 0
    Last Post: 02-11-2009, 07:33 PM
  5. jsp:include and include file
    By Heather in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-14-2007, 04:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •