Handlebars-Net / Handlebars.Net.Helpers

Handlebars.Net helpers in the categories: 'Boolean', 'Constants', 'Enumerable', 'Environment', 'Math', 'Regex', 'String', 'DateTime' and 'Url'.
MIT License
40 stars 15 forks source link

Helper with name "Not" not found #98

Closed chandraarora closed 3 months ago

chandraarora commented 3 months ago

Hi

It seems to me that i am doing a syntax or it is able able to find the help "not". could you please the below code and if am using not is right way.

using HandlebarsDotNet;
using HandlebarsDotNet.Helpers;

namespace test.Handlebars
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");

            string source =
@"{
    ""testFilter"": {

      ""enum"": [ {{#each data}}  {{#if ( not @first) }}  }} , ""{{this}}"" {{else}} ""{{this}}""{{/if}} {{/each}}],

}";

            var handlebarsContext = HandlebarsDotNet.Handlebars.Create();
            HandlebarsHelpers.Register(handlebarsContext);

            var template = handlebarsContext.Compile(source);
            var data1 = new 
            {
                data = new[] { "text1", "text2", "text3" }

            };

            var result = template(data1);

        }
    }
}
StefH commented 3 months ago

Maybe try this:

{{#each data}}
  {{#if @first}}
    "{{this}}"
  {{else}}
    , "{{this}}"
  {{/if}}
{{/each}}
chandraarora commented 3 months ago

Thank you, I saw in the code there is not operator , would it be possible to use it, just for my knowledge

Sent from Outlook for iOShttps://aka.ms/o0ukef


From: Stef Heyenrath @.> Sent: Sunday, June 23, 2024 9:13:38 AM To: Handlebars-Net/Handlebars.Net.Helpers @.> Cc: Chandra Arora @.>; Author @.> Subject: Re: [Handlebars-Net/Handlebars.Net.Helpers] Helper with name "Not" not found (Issue #98)

Maybe try this:

{{#each data}} {{#if @first}} "{{this}}" {{else}} , "{{this}}" {{/if}} {{/each}}

— Reply to this email directly, view it on GitHubhttps://github.com/Handlebars-Net/Handlebars.Net.Helpers/issues/98#issuecomment-2184754509, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIRM7FW2MYUFPEXADSHOVHLZIZYSFAVCNFSM6AAAAABJYDLLX2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBUG42TINJQHE. You are receiving this because you authored the thread.Message ID: @.***>

StefH commented 3 months ago

It is supported.

See https://github.com/Handlebars-Net/Handlebars.Net.Helpers/blob/master/test/Handlebars.Net.Helpers.Tests/Templates/BooleanHelpersTemplateTests.cs

use Boolean.Not or set the config to : https://github.com/Handlebars-Net/Handlebars.Net.Helpers?tab=readme-ov-file#without-a-prefix

chandraarora commented 3 months ago

Thank you it worked