Expand my Community achievements bar.

SOLVED

Different behavior of path/url with sightly

Avatar

Level 2

Hi, I am working with sightly in a template that has a link to redirect to the parent page, I can access the path of the parent wit this: currentPage.parent.path, this give me the complete path of the parent.

But also I need that with a extension .html in author environment (wcmmode enabled and disabled), and with a / in production.

How can I do that? Its possible with sightly or I should look a SlingModel solution?

Thank you in advance

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

if you use this solution make sure you remove wcmmode.disabled while checking author because wcmmode.disabled return true in publish environment.

so you can modify condition like <div data-sly-test.author="${wcmmode.edit || wcmmode.design  || wcmmode.preview}">

if you want to get runtime mode in HTL you can use java or JS and read wcm mode from sling model like below

@Inject

    private SlingSettingsService settings;

public Boolean getAuthorRunMode() {

    author = settings.getRunModes().contains("author");

        return author;

   }

Thanks

Arun



Arun Patidar

View solution in original post

3 Replies

Avatar

Community Advisor

Hi,

You can get wcmmode in sightly. based on that you can render content.

HTL introduction part 1

e.g.

<div data-sly-test.author="${wcmmode.edit || wcmmode.design || wcmmode.disabled || wcmmode.preview}">

  Show this to the author - Parent  Page -  ${currentPage.parent.path}.html

</div>

<div data-sly-test="${!author}">

  Not in author mode anymore..

</div>

Thanks

Arun



Arun Patidar

Avatar

Level 2

Hi, yes, I already know that, but Im looking for a cleaner way, if this exists and it's worth to do.

I found this <a href="${link} @ extension = 'html'" this seems work with JcrResourceResolverFactory, but I donk know yet how this will work on the publish instance.

Thanks for your help anyway! that will be one of my possible solutions

Avatar

Correct answer by
Community Advisor

Hi,

if you use this solution make sure you remove wcmmode.disabled while checking author because wcmmode.disabled return true in publish environment.

so you can modify condition like <div data-sly-test.author="${wcmmode.edit || wcmmode.design  || wcmmode.preview}">

if you want to get runtime mode in HTL you can use java or JS and read wcm mode from sling model like below

@Inject

    private SlingSettingsService settings;

public Boolean getAuthorRunMode() {

    author = settings.getRunModes().contains("author");

        return author;

   }

Thanks

Arun



Arun Patidar