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

[Question] How to output a form feed character in a template #593

Open
klreeher opened this issue Sep 25, 2024 · 0 comments
Open

[Question] How to output a form feed character in a template #593

klreeher opened this issue Sep 25, 2024 · 0 comments
Labels

Comments

@klreeher
Copy link

klreeher commented Sep 25, 2024

I have a handlebars template that looks like so:

{{#each thing}}
... bunch of straight forward templating ...
{{/each}}
{{{formFeed}}}

The form feed character is \f or https://unicodeplus.com/U+000C
I need my list of things to be output with a form feed character after each thing gets templated. I've tried a couple different things, including:

template:

{{#each thing}}
... bunch of straight forward templating ...
{{/each}}
{{{\f}}}

None of these, when I write the compiled text to file, actually have the form feed character.

I've tried tackling this through the writing to file side, thinking it was something there, but if I only template the thing section and write the form feed character like this, it works:

            using (StreamWriter sw = new StreamWriter(File.Open(outputFile, FileMode.CreateNew), Encoding.Unicode))
            {
                foreach (var thing in thingData)
                {
                    var text = RenderThing(ticket); // this is the handlebars.compile(template + data)
                    sw.WriteLine(text);
                    sw.WriteLine("\f");
                }

            }

This is not an ideal solution because one of the values the template uses for the looped things is the index of the thing in the list, but I can't figure out how to get the template to actually include the real form feed character.

If I pass the formfeed character in with the template data, like this:

        public string RenderThing(List<ThingObject> thingData)
        {
            string compileText = "{{> " + _templateName + "}}";
            _patternTemplate ??= _handlebars.Compile(compileText);

            var data = new
            {
                tickets = thingData,
                formFeed = "\f"
            };

            var text = _patternTemplate(data);
            return text;
        }

and I have the {{{formFeed}}} outside the #each loop, then I can get the form feed character to show up at the end. But if I try to move it into the loop, it's not rendered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant