Expand my Community achievements bar.

How do I implement dynamic sling selector?

Avatar

Level 8

TLDR: I want setup an AEM page that accepts firstname and lastname as parameter using an SEO friendly URL.

Going to www.host.com/mycontent.richard.williams.html will display a properly formatted/styled page with information relevant to Richard Williams.

If I go to www.host.com/mycontent.john.smith.html, the page will display information relevant to John Smith.

------------------------------

SEO friendly example: www.host.com/mycontent.richard.williams.html

not SEO friendly example: www.host.com/mycontent.html?firstname=richard&lastname=williams

------------------------------

So I've been following this guide (not sure if this is the best example/guide to help me): http://www.aemcq5tutorials.com/tutorials/sling-servlet-in-aem/

And while it works well for my the example

@SlingServlet(resourceTypes="geometrixx/components/hompepage", selectors={"firstname","lastname"}, extensions="html",methods="GET", metatype=true)

I am trying to make it dynamic.

At the moment, I can only access the servlet if access via: http://localhost:4502/content/geometrixx/en.firstname.lastname.html

I want to make firstname and lastname dynamic parameters/selectors. Like if for example I want to pass the values "richard.williams", I can then use: http://localhost:4502/content/geometrixx/en.richard.williams.html

if I try to use http://localhost:4502/content/geometrixx/en.richard.williams.html  right now, I get a blank page.

So basically I want to use selectors for passing parameter values to my page.

Any ideas how this can be done?

ps. At the moment, I only testing/experimenting in my local instance of AEM.

0 Replies