Dynamic CAML filtering
Currently, all web parts that use CAML for filtering require a static block of text for the query, with no way to change it at run time. This means that the filtering defined in the web part must be hard coded. This is highly inflexible -- what is needed is some way for the web parts to be sensitive to values passed into the page where the web part resides, via something like the URL query string. For example, let's suppose I want to create a news archive for hundreds of news items going back over ten years, with one year displayed at one time. The URL might look like:
/sites/mysitename/SitePages/archive.aspx?year=2017
I should be able to have a News WP on the page that will make use of the '2017' value in the CAML filter:
<Query>
<Where>
<And>
<Eq>
<FieldRef Name='NewsYear' />
<Value Type='Number'>{{{YearFromQueryString}}}</Value>
</Eq>
<Eq>
<FieldRef Name='ApprovalStatus' />
<Value Type='Choice'>Approved</Value>
</Eq>
</And>
</Where>
</Query>
I’d like to be able to map the query string value of '2017' to the label {{{YearFromQueryString}}}. Just like I am mapping the display values Title and so on, the properties panel of the web part should allow me to map 'YearFromQueryString' (one or more tokens that I define) to the value of 'year' (a value that I pass in on the URL).
That way I only need ONE page and ONE web part configured ONCE to display all of the news items for ANY year. Without something like this I need multiple web parts, each one configured (hard coded, basically) for each single year, and then additionally I would have to make a new one at the end of each year.
Thanks for listening.