ASPX templates
Version 3.x > ASPX templates > passing c# parameter into kentico transformation View modes: 
User avatar
Member
Member
whiplash - 10/30/2013 6:08:49 AM
   
passing c# parameter into kentico transformation
Hi

I have a CMSRepeater as follows


<cms:CMSRepeater ID="rptKeywordSearch" runat="server" ClassNames="cms.MenuItem" Path="/%"
TransformationName="cms.MenuItem.SimpleList" MaxRelativeLevel="3" ZeroRowsText="">
<HeaderTemplate>
<ul class="keywordSearch">
</HeaderTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</cms:CMSRepeater>


In the transformation I am trying to read a value from the QueryString, I want to pass this into the new function I have which reads in the 'Keywords' field (csv'd values) and a search term.

The function reads the keywords field, splits out the string into an array and does a boolean check to see if the search term exists within the array, returns true if it does and false if it doesn't.


<%
string searchTerm = Request.QueryString.Get("searchtext");
%>

<li class="<%# MyFunctions.getKeyword(Eval("Keywords").ToString(), Request.QueryString.Get("searchtext"))%>"><%# GetDocumentLink() %></li>
<!--<li class="<%# MyFunctions.getKeyword(Eval("Keywords").ToString(), "car")%>"><%# GetDocumentLink() %></li>-->



The commented out line in the transformation works as expected, but now I want to dynamically pass in the search term (from the query string)

the repeater then returns values adding true or false to the class of each li

I then used CSS to hide (display:none;) on the items that have false applied. However, I have been told that this may not be acceptable for SEO and accessibility reasons.

Can anyone shed any light?

Thanks

User avatar
Member
Member
whiplash - 10/30/2013 7:19:57 AM
   
RE:passing c# parameter into kentico transformation
The ideal solution to this would be to only return/render the documents as list items that contain a keyword stored in the keyword field (before the data is returned to the repeater)

Has anyone any suggestions?

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 10/31/2013 3:55:42 AM
   
RE:passing c# parameter into kentico transformation
Hello,

Thank you for your message.

If I understand you correctly I think you should be able to pullout the query string through our query string macro ( http://devnet.kentico.com/docs/devguide/types_of_macros.htm#querystring )

You can pullout the query string like:


{%querystring_key%}


And then pass this to your macro method.

Let me know how it works.

Kind regards,
Richard Sustek

User avatar
Member
Member
whiplash - 10/31/2013 10:04:49 AM
   
RE:passing c# parameter into kentico transformation
Hi,

thanks for the reply.

I had tried to pass a macro into the Function.MethodName which I was trying to apply to the LI's class name, but it didn't work.

I had a rethink of the task I was trying to do and I set the items that were not keywords to visible=false and rebound the repeater.

It worked :)