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

[Feature request] Support for nested objects inside template builder. #405

Open
sunnysonx opened this issue Jan 7, 2021 · 0 comments
Open

Comments

@sunnysonx
Copy link

Feature request

Please describe your feature request

Add support for nested objects inside the template builder.

Example

let page = {
    "id": "1",
    "page_title": "My test page",
    "page_body": "some text here",
    "page_slug":"my-test-page",
    "menu_item":{
        "name":"Homepage",
        "slug":"homepage"
    }
}

let template = new URITemplate("http://example.org/{menu_item.slug}/{page_slug}");
let result = template.expand(page);

// result = http://example.org/homepage/my-test-page

Why is it needed?

  • Because it's nice to have such a feature, simplifies things.
  • Avoids the necessity to manually expand the template and allows you to directly provide the object.

Suggested solution(s)

  • A solution would be to use the same approach as lodash uses for get() https://lodash.com/docs/4.17.15#get, as it returns the value based on the path, for current example, _.get(page,'menu_item.slug') will return the homepage
@sunnysonx sunnysonx changed the title Support for nested objects inside template builder. [Feature request] Support for nested objects inside template builder. Jan 7, 2021
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

No branches or pull requests

1 participant