Skip to content

Instantly share code, notes, and snippets.

@yupadhyay
Last active February 7, 2016 20:35
Show Gist options
  • Save yupadhyay/92d4fab81439a322e58e to your computer and use it in GitHub Desktop.
Save yupadhyay/92d4fab81439a322e58e to your computer and use it in GitHub Desktop.
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