You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "Pierre Villard (Jira)" <ji...@apache.org> on 2022/01/11 11:30:00 UTC

[jira] [Commented] (NIFI-9561) Apply (Handlebars) Template Processor

    [ https://issues.apache.org/jira/browse/NIFI-9561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17472667#comment-17472667 ] 

Pierre Villard commented on NIFI-9561:
--------------------------------------

Aren't you looking for the ReplaceText processor with the Substitute Variables strategy?

Basically: if you have flow file content containing

${foo} ${faa}

This would be replaced by the value of the foo and faa attributes of the flow file.

> Apply (Handlebars) Template Processor
> -------------------------------------
>
>                 Key: NIFI-9561
>                 URL: https://issues.apache.org/jira/browse/NIFI-9561
>             Project: Apache NiFi
>          Issue Type: Wish
>            Reporter: Cemre Mengu
>            Priority: Minor
>         Attachments: image-2022-01-11-13-50-47-295.png, image-2022-01-11-13-56-36-444.png
>
>
> Recently, I was trying to to create json/xml payloads from attributes to be used as requests. In most of the cases I had a template request to be filled with attributes. However, the easies way I could find was to use ReplaceText multiple times for individual replacements and for a large payload I had a long line of ReplaceText processors (as shown)
> !image-2022-01-11-13-50-47-295.png!
> When there isnt a template for request this can be done sub-optimally (I think) with AttributesToJson or JoltTransform processors (as discussed here [https://stackoverflow.com/questions/50415016/nifi-atttributes-to-json-not-able-to-generate-the-required-json-from-an-attr])
> I would like to propose a new processor called ApplyTemplate where the processor simply applies matching attributes to the provided template string. In terms of java this will be something like:
> ```
> Handlebars handlebars = new Handlebars();
> Template template = handlebars.compileInline("Hello {{{{{}this{}}}}}!");
> System.out.println(template.apply("Handlebars.java"))
> ```
> using [https://github.com/jknack/handlebars.java]
> This processor will dramatically simplify most of the tasks and the implementation is very simple. If this is something you would consider adding to core, I am ready to provide and work on the PR.
> The processor config looks like this where node_ip, port etc. are attributes of the incoming flowfile which will be applied to template and result will be written to flowfile content
> !image-2022-01-11-13-56-36-444.png!



--
This message was sent by Atlassian Jira
(v8.20.1#820001)