Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#782·ejs

Function to return JS object containing EJS template bindings structure.

Author: Jack-OverflowCreated Apr 7, 2025Updated Jan 17, 2026

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?

Source: mde/ejs

View original on GitHubView discussion on GitHub