Skip to content

feature request: allow resource precompiling #198

@jantimon

Description

@jantimon

the @adobe/htlengine supports two ways to include content into a template:

data-sly-call

The directive data-sly-use is executed during compile time and uses the @adobe/htlengine templateLoader to include the html file.
During runtime it executes the template:

<sly 
  data-sly-use.teaserItem="project/components/content/articleTeaser/teaserItem.html"
  data-sly-call="${primaryLinkTmpl.teaserItem @ someData=something}"
/>

data-sly-resource

The directive data-sly-resource is executed only during runtime and therefore we are not able precompile the template in project/components/content/articleTeaser/teaserItem although it is already known.

<sly 
  data-sly-resource="${'teaserItem' @ resourceType='project/components/content/articleTeaser/teaserItem'}"
/>

will be compiled to: const var_resourceContent1 = yield $.slyResource("teaserItem", {"resourceType": "project/components/content/articleTeaser/teaserItem", });

Would it be possible to add a feature similar to the defaultModuleGenerator which allows custom precompiling for data-sly-use also for data-sly-resource?

The main motivation behind this feature request is the goal to run data-sly-resource inside a browser without the need of a running server to render the resource template.

Right now the compiler accepts a moduleMap with the argument called mods:

const parseResult = await this._parse(source, baseDir, mods);

One idea how we might achieve add is new feature would be to rename mods to meta and allow a substructure like this

meta = {
   mods: { /* all previous module mappings */ },
   resources: { /* resource values */ },
}

That way we could add a preprocessor api for the resources and allow modifications during compile time:

compiler
  .withResourceLoader(function(resource) {
     console.log(resource); // -> {"resourceType": "project/components/content/articleTeaser/teaserItem"}
     return JSON.stringify(resource);
  })

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