Return in Sightly

Avatar

Avatar

rk39193348

Avatar

rk39193348

rk39193348

06-02-2017

Hi,

I have a basic example in sightly which is as below: In the logs the value of string 'value' gets printed but in the page it is not getting printed. Please let me know how to achieve this

<div data-sly-use.component="com.adobe.cq.Component">
<p> from java resource: ${component.value}</p>
</div>

In my java class Component.java

package com.adobe.cq;
import com.adobe.cq.sightly.WCMUse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.sling.api.resource.Resource;

public class Component extends WCMUse
{
private String value;
private static final Logger LOGGER = LoggerFactory.getLogger(Component.class);

@Override
  public void activate() throws Exception
   {
  Resource resource = getResource();
  value = resource.getPath();
  LOGGER.info(" value****"+value);
  }
public String getvalue()
{
 return value;
  }
}

View Entire Topic

Avatar

Avatar

Gdubz-57m2mu

Avatar

Gdubz-57m2mu

Gdubz-57m2mu

07-02-2017

Feike Visser wrote...

@greg, great catch!

In this case there is no real need for Java, you can have this too in your component:

${resource.path}

 

Thanks, and I completely agree, a lot of the common functionality is available without writing your own custom classes.

What I posted should work if he or she is really determined to use Java instead. Like if they intend to take this and extend it further, and were merely using the resource.getPath(); as a simple example to pose the question with.