开发者

How do I write a Sitecore query from media item template to correct Home item with multiple sites?

I have a custom media item template that allows users to add category filters to the uploaded file. The media item is kept in the media library. The filters are to be selected from a folder underneath the Home item of relevant site in the content tree. They are selected using a treelist control. We have multiple sites, each will have their own Home item and filter folder. I need to set the source of the treelist control to point to the relative filter folder for each site.

If the media item were under the Hoe item I could use this:

query:ancestor-or-self::*[@@templatename='Home']/item[@key='filters']

But of course the media item won't find ancestor-or-self::*[@@templatename='Home'] as it 开发者_如何学Pythonisn't on that branch, it's parallel.

I doubt our naming standard will be robust enough to ensure any relative path based entirely on item names, and I'd rather avoid having to concatenate a name of a media folder to find the correct name of the Home item.

Is there any way of solving this elegantly?

I could of course put the filters folder elsewhere, either in the Media library (would rather avoid this as it will not be intuitive to our business users) or in a global section (where they would have to find their own specific site folder below - or add another security configuration to the content tree).


The getLookupSourceItems pipeline would allow you to add custom tokens/syntax to the Source field, e.g. a lookup to the correct site's home item.

http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/05/Reference-the-Context-Item-and-System-Date-in-the-Source-Property-of-Sitecore-ASPNET-CMS-Fields.aspx

However from what I can gather, TreeList does not use this pipeline. Thus another option might be to create a custom TeeList field type.

http://www.cmssource.co.uk/blog/custom-tree-list


Answering my own question:

This isn't possible to do without employing some form of naming standard. If the branches within the media library mirror the branches within the content tree (Site1, Site2, Site3 etc) then a naming standard could enforce the correct relation between a media library branch and a content tree branch. If no such naming standard and branch mirroring is in place then there is no way of connecting a media folder with a specific site without adding a configuration item of some sort to contain the reference.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜