0

As of HTL 1.4, it is possible to access a resource if you know its path by using data-sly-use, e.g.: data-sly-use.item="/content/my_nodes/node1"

However, if one does not have the path to the resource, but only the node's jcr:uuid (automatically generated through use of mix:referenceable), is there any way that one can look up the resource with a similar HTL statement?

Spinner
  • 732
  • 1
  • 6
  • 21

1 Answers1

1

There is no such convenience, at the moment. However, the HTL specification does not exclude this and you should be able to write your own UseProvider implementation. You can have a look at the ResourceUseProvider for inspiration.

Vlad
  • 10,602
  • 2
  • 36
  • 38
  • 1
    In theory that would be an option, but wouldn't it be much simpler to have a `SlingModel` get the path to the resource? – Jens Jun 11 '19 at 07:35
  • 2
    @Jens, the simplest way is to have a generic Use POJO that can take in a UUID as a parameter (expression attribute) and returns the corresponding resource. However, that's not what the OP asked for. Also, if they decide to implement their own UUIDResourceUseProvider, they could contribute that to Sling and others could use it too. – Vlad Jun 11 '19 at 10:06
  • @Vlad Thanks. I'm now writing my own UseProvider, which shows as a component in the Sling Console, but seemingly isn't receiving requests to resolve identifiers. Is there anywhere to view all registered Sling Use Providers in the Sling Console? – Spinner Jul 08 '19 at 14:05
  • Turns out it was an obscure class loading problem that was allowing the new UseProvider to launch as a component but never calling its provide() method. – Spinner Jul 29 '19 at 11:12
  • @Vlad I've uploaded to GitHub my initial [UUIDResourceUseProvider implementation](https://github.com/SpinnerWebs/sling-uuid-useprovider), which I'd be happy to contribute to Sling, if it's considered useful. – Spinner Jul 29 '19 at 11:16
  • 1
    @Spinner I would first make sure the identifier matches an UUID pattern before attempting to read the corresponding JCR node. You can have a look at https://github.com/apache/sling-org-apache-sling-scripting-sightly-models-provider/blob/master/src/main/java/org/apache/sling/scripting/sightly/models/impl/SlingModelsUseProvider.java#L97 for inspiration. – Vlad Jul 30 '19 at 13:09
  • @Vlad Good idea, have added validation. – Spinner Jul 30 '19 at 15:14
  • @Spinner, I think the best way forward is to create a Sling Jira issue a https://issues.apache.org/jira/projects/SLING and get a proper review for your contribution – Vlad Jul 30 '19 at 15:16