Last active
February 7, 2016 20:35
-
-
Save yupadhyay/92d4fab81439a322e58e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wemblog.sightly.use | |
@Model(adaptables = SlingHttpServletRequest.class) | |
public class ExternalUrl { | |
@Inject | |
private Externalizer externalizer; | |
@Inject // Using the bindings from Sightly (${currentPage.path} | |
protected Page currentPage; | |
@Inject @Optional // parameter from data-sly-use | |
protected String path; | |
@PostConstruct | |
protected void init() { | |
String relPath = currentPage.getPath(); | |
if ( path != null) { // check if there is a parameter | |
relPath = path; | |
} | |
absoluteUrl = externalize(relPath); | |
} | |
protected String externalize(String path) { | |
return externalizer.absoluteLink(request, "http", path); | |
} | |
} | |
#In your Sighly file | |
<meta data-sly-use.externalizer="${'wemblog.sightly.use.ExternalUrl' @ path=resourcePage.path}" | |
property="og:url" | |
content="${externalizer.absoluteUrl @ context='uri'}.html" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment