Forum Discussion
Content Search WebPart
Can you explain the scenario why you are re-issuing the query inside the display template?
If you explain the scenario I'm sure there is a solution.
- Sumit GargMay 10, 2017Copper Contributor
Hi Mikael
I need to dynamically filter results of CSWP based on a value of user profile property of current logged in user and on my page I have multiple CSWP's so to ensure that I change query only of a particular webpart I am using $getClientControl($("#<element ID>")[0]) to get CSWP object and to ensure that display template element is rendered before calling "getClientControl" I am calling my custom method inside AddPostRenderCallback.
- Mikael SvensonMay 10, 2017Iron Contributor
Sumit Garg wrote:Hi Mikael
I need to dynamically filter results of CSWP based on a value of user profile property of current logged in user and on my page I have multiple CSWP's so to ensure that I change query only of a particular webpart I am using $getClientControl($("#<element ID>")[0]) to get CSWP object and to ensure that display template element is rendered before calling "getClientControl" I am calling my custom method inside AddPostRenderCallback.
Can't you for that one webpart use query variables in the query template to get the user property you need?
someproperty:{User.InternalPropName}
See http://www.techmikael.com/2014/05/s15e03-query-variables-constant-trouble.html for more information on this.
And it's better to put postrender in the control template, and not the item template, if that's what is needed.
- Sumit GargMay 11, 2017Copper Contributor
I can't directly use query variables as the user profile property values needs to be processed(trimmed) before it can be used in query filters/variables and I have used PostRender in control template only.