上一回中,小菜学会了修改和部署一个WebPart.
大师: 小菜,有几个很常用的WebPart你需要熟悉下. 先用那个Content Query Web Part做一个图片滚动的任务.示例已经发你了.
小菜: 得令.
使用CQWP实现一个图片走马灯的效果.(这个玩意儿一般网站首页都有的,就是那个会自动滚动切换的图片...)
小菜: Content Query Web Part 是 What?
小菜找到了如下解释:
This web part allows you to show items from your site based on a query, or set of rules, that you define. You can control what part of the site the web part looks for content, what types of items it returns, and it lets you filter, sort, and group those results. And, it lets you control how the items are rendered, so you can make these aggregations match the look and feel of the rest of your web site, both in what content is shown as well as how it's styled.
不管三七二十一,小菜先在界面上放好控件,有几个重要的属性需要设置.
小菜对site collection,list,content type 的概念都不熟悉,但是这个不妨碍小菜找到数据源.
小菜简单的设置完毕,已经在界面上显示出了不少东西,但是小菜知道重头戏是下面的xsl设置.
小菜新建了几个xsl去呈现获得的xml,这个时候必须注意区别ContentQueryMain.xsl,ItemStyle.xsl和Header.xsl,确保引用的正确.小菜因为没有仔细区别几个xsl而白白浪费了半个下午.
具体如何写xsl略去,这个玩意儿和html类似,上手比较容易.
小菜学习了Content Query Web Part的使用.
小菜: 刚开始把ContentQueryMain当ItemStyle.xsl在用,结果各种诡异的问题层出不穷.
大师: 那你以后该如何避免这个问题呢?
小菜: 首先必须彻底搞清楚这几个xsl的区别,再次对于一般的Item Style修改可以直接在系统默认的文件上增加新的Style就行了.
小菜: 如果非用增加新的xsl文件,记得新建好文件夹,对应的文件名要带上*ItemStyle.xsl或者*ContentQueryMain.xsl的后缀.
大师:
ContentQueryMain.xsl
Contains logic that generates the appropriate calls to the Header and Item templates for each item.
Contains functions that help designers modify the Item and Header XSLT transforms.
Receives all the content, parses it, and sends appropriate pieces to the ItemStyle and Header templates.
Maintains the structure of the Content By Query Web Part.
Stores data retrieved when querying content in the path/dsQueryResponse/Rows/Row.
ItemStyle.xsl
Contains templates that define how to display an item. These templates receive and process one row of data at a time, ensuring that the style and data in the item rows is consistent.
You can retrieve data about a row by using the @Propertydirective.
Header.xsl
Contains templates that define how to display a header and ensure the consistency of group headers.
Templates specified in Header.xsl receive the next item row to process, usually the first row in a group unless there are multiple columns. If there are multiple columns, the templates receive the first row of the column.
You can retrieve data about the next item row by using the@Property directive. You can use the $Group parameter that contains the groupby column name and the $GroupType that represents the column type of the groupby column.
小菜:...? What?