Determining the selected Keyword
To get the value of the currently selected Keyword in a website that uses taxonomy-based navigation, you need to add presentation-side code to get and pass the value of the Keyword.
- To get the value of the currently selected Keyword, use the Taxonomies API (Tridion Sites Content Delivery API.
- To pass the value of the Keyword in the query, use the Experience Optimization Content Delivery API available as ASP.NET
- ASP.NET example
-
The following ASPX example finds the query on the webpage using the Element ID of the Server Control (
"MyID") and passes a (hardcoded) Keyword value into the query:<head runat="server"> <script runat="server" language="c#"> void Page_Load(object sender, System.EventArgs e) { Query query = Page.FindControl("MyID") as Query; if (query != null) { query.SetSelectedKeyword("tcm:161-875-1024"); } } </script> </head> - Java example
-
The following JSP example passes a (hardcoded) Keyword value into the query by setting an attribute on the
PageContextobject whereMyIDin"MyID_keywordUri"iselementIdis the ID of the custom tag andkeywordUriis the Keyword to pass:<% String selectedKeywordUri = "tcm:161-875-1024"; pageContext.setAttribute("MyID_keywordUri", selectedKeywordUri,PageContext.PAGE_SCOPE); %>