Skip to content

Conversation

nevaeh5379
Copy link

@nevaeh5379 nevaeh5379 commented Sep 5, 2025

PR Checklist

  • Have you checked if it works normally in all models? Ignore this if it doesn't use models.
  • Have you checked if it works normally in all web, local, and node hosted versions? If it doesn't, have you blocked it in those versions?
  • Have you added type definitions?

Description

The Problem

The previous implementation of the {{call::...}} syntax used a simple string.split('::') method to parse its arguments. This had a critical limitation: it could not correctly handle arguments that contained nested CBS (e.g., {{getvar::...}}, {{slot::...}}). This made it impossible to use powerful patterns, such as calling a function with a dynamic value from within an {{#each}} loop.

The Solution

This PR replaces the simple split logic with a more robust, context-aware parser for {{call}} arguments. The new implementation iterates through the argument string while tracking the nesting level of curly braces ({{...}}). As a result, it now correctly identifies :: as a top-level argument separator, while ignoring any :: found inside nested syntaxes.

Key Improvements

  • Nested CBS in Arguments: {{call}} can now safely accept other CBS as arguments, enabling dynamic and modular script creation.
  • Enhanced Scripting Patterns: This allows for advanced use cases, like using {{#each}} to loop through an array and call a function for each item, as demonstrated below.

Demonstration

The following test case now works as intended.

Test Code:

{{settempvar::my_fruits::{{array::Apple::Banana::Cherry}}}}

{{#func render_item}} 
  <div class="item">
    {{#when::{{arg::1}}::isnot::Banana}}
      - Fruit Name: {{arg::1}}
    {{:else}}
      - This one is a Banana!
    {{/when}}
  </div>
{{/func}}

<div class="fruit-list">
  {{#each {{gettempvar::my_fruits}} fruit}}
    {{call::render_item::{{slot::fruit}}}}
  {{/each}}
</div>

Before:

The parser failed because it incorrectly split the nested {{slot::fruit}} and {{when...}} syntaxes, leading to broken output.
msedge_46ZN0CKbbh

After:

The function is called correctly for each item in the loop, producing the expected HTML structure.
msedge_Vv4zglW0co

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

Successfully merging this pull request may close these issues.

1 participant