Skip to content

feature request: provide current resource path to model and resourceLoader #227

Description

@jantimon

During runtime resources can be loaded recursively.

Example

For example if we would have the following resource loading:

main.htl 
   -> child.htl
       -> grandchild.htl
       -> grandchild.htl
click here to expand markup example

main.htl

<sly 
  data-sly-resource="${'resourceItem' @ resourceType='child'}"
/>

and in resourceItem you have

child.htl

<sly 
  data-sly-resource="${'childResourceItem1' @ resourceType='grandchild'}"
/>
<sly 
  data-sly-resource="${'childResourceItem2' @ resourceType='grandchild'}"
/>

grandchild.htl

<sly data-sly-use.myModel="com.foo.core.models.myModel"/>
${myModel.title}

Motivation

This resource path information is often used to return the according model data.
In the example above both grandchild.htl could render different data from the same model name.

API

It would be most convenient if the resourcePath could be an array e.g. ['root', 'resourceItem', 'childResourceItem1'] and would be available at two locations:

compiler.withModuleImportGenerator

Although the resourcePath is a runtime only value we could still provide it to the Model mapper e.g.:

compiler.withModuleImportGenerator((baseDir, varName, moduleId) => const ${varName} = function Model() { ...

could be changed to:

compiler.withModuleImportGenerator((baseDir, varName, moduleId) => const ${varName} = function Model(resourcePath) { ...

runtime.withResourceLoader

Inside the runtime it would also be nice to provide this resourceParameter for resource loading:

runtime.withResourceLoader((runtime, resourceName, resourceParameters) => {
runtime.withResourceLoader((runtime, resourceName, resourceParameters, resourcePath) => {

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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