Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render template that it is contains one '\r\n' string will return more than one #1087

Open
ClearScenery opened this issue Jun 27, 2023 · 0 comments

Comments

@ClearScenery
Copy link

render method with config withLstripBlocks(true).withTrimBlocks(true)

public static String render(String template, Map<String,Object> params) {
        final JinjavaConfig config = JinjavaConfig
                .newBuilder()
                .withLstripBlocks(true).withTrimBlocks(true).build();
        final Jinjava jinjava = new Jinjava(config);
        final JinjavaInterpreter jinjavaInterpreter = jinjava.newInterpreter();
        jinjavaInterpreter.getContext().putAll(params);
        final String renderStr = jinjavaInterpreter.render(jinjavaInterpreter.parse(template));
        return renderStr;
 }

test code:

  
         String template = "{% if bootefiDev %}\r\n" +
                "part /boot/efi --fstype=\"efi\" --size=500 --ondisk={{ bootefiDev }}\r\n" +
                "{% endif %}\r\n" +
                "{% if bootDev %}\r\n" +
                "part /boot --fstype ext4 --size=2048 --ondisk={{ bootDev }}\r\n" +
                "{% endif %}\r\n" +
                "{% if rootDev %}\r\n" +
                "part / --fstype ext4 --size=1 --grow  --ondisk={{ rootDev }}\r\n" +
                "{% endif %}\r\n";
        Map<String,Object> param = new HashMap<>();
        param.put("bootefiDev","sda");
        param.put("bootDev","sda");
        param.put("rootDev","sda");
        System.out.println(render(template,param));
 

and then i will get a render result below:

part /boot/efi --fstype="efi" --size=500 --ondisk=sda


part /boot --fstype ext4 --size=2048 --ondisk=sda


part / --fstype ext4 --size=1 --grow  --ondisk=sda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant