Sorguya ihtiyacınız yoktur - alt tablo veri kaynağı konumu yalnızca göreli bir yol kullanabilir. Örneğin.
./Items
Açıkçası, bu klasörün zaten mevcut olması gerekir. Bu kodun blogunu oluşturdum, ve bu aşırı bir olasılık olabilir ama size yardımcı olabileceğinden buradan yayınlayacağım. Zaten mevcut değilse, göreceli bir yol veri kaynağı konumu oluşturmak için getRenderingDatasource
boru hattına aşağıdakiler eklenebilir. GetDatasourceLocation
işlemcisinden önce ekleyin.
Sublayout'ta, oluşturulacak öğenin şablonunu belirtmek için contentFolderTemplate=[GUID]
parametresini eklemek istersiniz.
public class CreateContentFolder
{
protected const string CONTENT_FOLDER_TEMPLATE_PARAM = "contentFolderTemplate";
public void Process(GetRenderingDatasourceArgs args)
{
Assert.IsNotNull(args, "args");
Sitecore.Data.Items.RenderingItem rendering = new Sitecore.Data.Items.RenderingItem(args.RenderingItem);
UrlString urlString = new UrlString(rendering.Parameters);
var contentFolder = urlString.Parameters[CONTENT_FOLDER_TEMPLATE_PARAM];
if (string.IsNullOrEmpty(contentFolder))
{
return;
}
if (!ID.IsID(contentFolder))
{
Log.Warn(string.Format("{0} for Rendering {1} contains improperly formatted ID: {2}", CONTENT_FOLDER_TEMPLATE_PARAM, args.RenderingItem.Name, contentFolder), this);
return;
}
string text = args.RenderingItem["Datasource Location"];
if (!string.IsNullOrEmpty(text))
{
if (text.StartsWith("./") && !string.IsNullOrEmpty(args.ContextItemPath))
{
var itemPath = args.ContextItemPath + text.Remove(0, 1);
var item = args.ContentDatabase.GetItem(itemPath);
var contextItem = args.ContentDatabase.GetItem(args.ContextItemPath);
if (item == null && contextItem != null)
{
string itemName = text.Remove(0, 2);
//if we create an item in the current site context, the WebEditRibbonForm will see an ItemSaved event and think it needs to reload the page
using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext("system")))
{
contextItem.Add(itemName, new TemplateID(ID.Parse(contentFolder)));
}
}
}
}
}
}
Aradığım şey, ayrıntılı yanıt için teşekkürler. –
@ techphoria414 Subcoreout veri kaynağındaki göreceli yolu desteklemek için hangi Sitecore sürümünü kullanıyordunuz? Bu, birkaç proje için yapmak istediğim bir şey ... –
6.4.1, bu Sayfa Düzenleyicisi tarafından kullanılan alt-harmanın Veri Kaynağı Konumunda olmasına rağmen. Öğe seçildikten sonra, hala mutlak bir yoldur (bir öğede GUID olarak değiştiririz: kaydetme işleyicisi). Genel olarak bir veri kaynağındaki göreceli yolları desteklemek istiyorsanız, SublayoutParamHelper yardımcı program sınıfını (veya sürümünüzü) bir GetItem yerine bir Sitecore Sorgusu yapmak için özelleştirebilirsiniz. – techphoria414