开发者

How can I use the Inversion of Control concept in Sitecore to get non-page items to display themselves?

开发者 https://www.devze.com 2023-04-08 13:58 出处:网络
I have a number of non-page content items that are used as \"callouts\" on the side of pages throughout my website that I am building in Sitecore.Ideally I would like to be able to define the presenta

I have a number of non-page content items that are used as "callouts" on the side of pages throughout my website that I am building in Sitecore. Ideally I would like to be able to define the presentation information for these callouts independen开发者_运维技巧tly. Then when a CMS author selects callouts for a particular page in the site, they know how to display themselves. I read an excellent blog post about how to do this here: http://www.awareweb.com/AwareBlog/InversionControl2.aspx. I used the first method that he describes in the post.

However my implementation of that code doesn't completely work. It seems to get the correct rendering and it iterates properly through the selected non-page callout items. But when it displays them on the page it seems like the callout items are still using Sitecore.Context.Item as their source item and not the source item that was passed in to them via the strDataSource variable as seen in the example code.

Do I have to do anything special in the code behind for the sublayouts for the callouts to tell them not to use Sitecore.Context.Item and instead to use the source item that was passed in? Otherwise I can't figure out why it's not working. Any ideas?

Thanks, Corey


Setting the DataSource in a sublayout doesn't explicitly set the Context.Item to a different value, it just sets a property in a sublayout that it can use itself.

Rather than write up the solution again, John West's blog already covers this subject here, so I'd recommend you read that - http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/How-to-Apply-Data-Sources-to-Sitecore-ASPNET-Presentation-Components.aspx

I would recommend using the SublayoutParameterHelper Shared Source library which provides a Helper and a base class to use with your sublayouts for accessing the Item represented by an ID set in the DataSource; John also cites this library in his blog post.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号