Link and tree field to current site context - sitecore

In multiple sites, is it possible to make the link and tree field to map to current website context in Sitecore ?

In your case you need to use relative source for your fields.
For the tree list you can use:
datasource=query:./ancestor-or-self::*[##templatename='Site']/*

Related

sitecore 7 multi datasource field

I have a treelist field that I want to set the datasource to 3 folders p.e.:
/sitecore/Website/News/
/sitecore/Website/Events/
/sitecore/Website/Articles/
Under the website item there are more "folders".
I've searched and spent few hours trying different approaches but none seemed to work.
Is this possible? Do I need to extend the field?
Thank you in advance
A while back I wrote a blog post about the different ways you can control the Datasource of your multilist and treelist fields (with and without search). The third technique listed for fields with search is what I think you are looking for:
Search in two or more places of the content tree (Fields with Search):
StartSearchLocation={110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}&Filter=_path:110d559fdea542ea9c1c8a5df7e70ef9|_path:3d6658d8a0bf4e75b3e2d050fabcf4e1
For your implementation:
StartSearchLocation={Website.ID}&Filter=_path:[News.ID (guid form; no brackets)]|_path:[Events.ID (guid form; no brackets)]|_path:[Articles.ID (guid form; no brackets)]
Search in two or more places of the content tree (Fields without Search):
If you are using a Multilist field (without search) then I would do the following:
DataSource=/path/to/source/1|/path/to/source/2
For your implementation:
DataSource=/sitecore/website/news|/sitecore/website/events|/sitecore/website/articles
I would also add that the Treelist with Search field has been deprecated in later versions of Sitecore 7, so if that is the field that you are using then I advise changing to the Multilist with Search field. If you are using a standard Treelist field, then Ahmed's answer may be viable as well, depending on your use case.
Let me know if you have any questions. Good luck, and happy coding! :)
You can use IncludeTemplatesForDisplay parameter to filter the items based on templates:
DataSource=/Sitecore/Content/Home&IncludeTemplatesForDisplay=News Folder,News,Event Folder,Event
IncludeTemplatesForDisplay parameter accepts comma separated templates names, you might need to include parent folder templates names too so that it appear in treelist.
Hope this helps

How to arrange items in descending way in sitecore using sitecore news-mover model?

I am working on sitecore project,where I have to access items in descending form.
How can I access Sitecore news mover model in descending order?
I am using Sitecore news mover model in my sitecore structure. Where I am accessing news mover model to accessing sitecore items in ascending way, but according to my project requirement how can I arrange the items in descending form?
I have tried to do with removing some item templates, but descending order is not appearing. Should I make any changes into other file?
We really need to see some code otherwise it is a total stab in the dark. Assuming that all you have to do is reverse the current order of the displayed item then you simple need to Reverse() the list, e.g.
var newsArticles = Sitecore.Context.Database.SelectSingleItem("/sitecore/content/home/news/2013").Axes.GetDescendants().Reverse();
You obviously need to handle the client "sort by asc/desc" functionality.
You might want to look at:
c# Trying to reverse a list
Of course, it would be much better to index and search using Lucene.
i solved this problem by simply add a config file in
App.config>>Include>>NewsMover.config
Then after specify your Template's path in NewsMover.config as following
<template id="user Defined/Home/Pages/Article Page" sort="Descending">
(Here Article Page is my Page Template which Created in user define Template section)

How to look up the document library in its local sub site where used, rather than in the root site?

I have a content type that has a lookup field for a document library in its sub site. The content type is declared a site collection root level but I want the look up field to look up the document library in its local sub site where used. I deploy the content types using PowerShell and have used an event receiver to add the look up field. I can't however get it to reference the correct list, it only ever references the list at the root site collection.
How can I overwrite the look up list?
I avoid setting the List attribute in the Field element. I have had problems saving the site as a template when a custom Field has the List attribute set. But the other problem is that these properties are write-once. Better to leave it blank in the definition and then set it in the instance programmatically using SPFieldLookup.LookupWebId and SPFieldLookup.LookupList.

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 isn'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.

Having The Source Field be the Link Provided in Another Sitecore Item

Suppose Item A contains the link Item B would like to use as the source of its Droplist field. How can I achieve this? I have read the Sitecore Query documentation here and here. It appears to me that this is not achievable using Sitecore query, but I could be mistaken. Any help would be appreciated.
No this is not possible. To set the source of a droplist, you can either set the root path to an item which would make the droplist populate the sub-items or you can use Sitecore query to query for specific items based on your query. This is covered in the Data Definition Cookbook (PDF link) under 2.4.2.