Pass variables from outer Snippet to inner Snippet

name:baz

age:30

currenttime:2017/06/26 14:54:40

  • This text is passed by outer snippet.(1)
  • This text is passed by outer snippet.(2)
  • This text is passed by outer snippet.(3)
/templates/passvariables.html
<section>
	<article>
		<div id="outer" afd:render="ComplicatedSnippet:outer">
			<div id="inner" afd:render="ComplicatedSnippet:inner">
				<p id="name">name:<span>name</span></p>
				<p id="age">age:<span>age</span></p>
				<p id="currenttime">currenttime:<span>currenttime</span></p>
				<ul id="list">
					<li>dummy list</li>
				</ul>
			</div>
		</div>
	</article>
</section>
/snippet/ComplicatedSnippet.java
public Renderer outer() {
    // prepare all necessary data for the inner snippet
    Renderer render = Renderer.create();
    render.add("div#inner", "name", "baz");
    render.add("div#inner", "age", "30");
    render.add("div#inner", "currenttime", new Date());

    List<String> list = new ArrayList<>();
    list.add("This text is passed by outer snippet.(1)");
    list.add("This text is passed by outer snippet.(2)");
    list.add("This text is passed by outer snippet.(3)");

    render.add("div#inner", "list", list);

    return render;
}

public Renderer inner(String name, int age, Date currenttime, List<String> list) {
    // receive the parameters by method declaration and then make use of them
    Renderer render = new GoThroughRenderer();
    render.add("p#name span", name);
    render.add("p#age span", age);
    render.add("p#currenttime span", DateFormatUtils.format(currenttime, "yyyy/MM/dd HH:mm:ss"));
    render.add("ul#list li", list);
    return render;
}