Skip to content

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

@sunnysonx

Description

@sunnysonx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions