Skip to content

Function to return JS object containing EJS template bindings structure. #782

Open
@Jack-Overflow

Description

@Jack-Overflow

I believe this issue has already been raised previously here, but it seems the original question may have been misunderstood.

I've also encountered this problem. In my use case, I want to generate a request schema based on the bindings within an EJS template. Ideally, I need a function that returns an object representing the variables used in the template.

For example, given this template:

<p><%- SomeRandomVar %></p>
<p><%- User.FirstName %></p>
<% for (let badge of User.Badges) { %>
  <p><%- badge.Name %></p>
<% } %>

I would expect something like:

{
  "SomeRandomVar": "string",
  "User": {
    "Badges": [
      {
        "Name": "string"
      }
    ]
  }
}

I don't need a fully fleshed out JSON schema but just getting some of the variable names from within the template would be a good start. Is there anything built into EJS already that provides this sort of functionality or would this be a new feature request?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions