2

I'm extending Sitecore.Shell.Applications.WebEdit.Commands.AddRendering, and from the code there's GetRenderingDatasourceArgs.DatasourceRoots and I am adding items on it:

var customdatasourceroot = "/sitecore/content//*[@@templateid='{templateid}']";
if (!string.isnullorempty(customdatasourceroot))
{
    var obj = renderingdatasourceargs.contentdatabase.getitem(renderingdatasourceargs.contextitempath);
    if (obj != null)
    {
        var objarray = (item[])null;
        objarray = obj.axes.selectitems(customdatasourceroot);

        if (objarray != null)
        {
            foreach (var item in objarray)
            {
                renderingdatasourceargs.DatasourceRoots.Add(item);
            }
        }
    }
}

But when the dialog box appears, only the nodes for the current datasource appears on the selection box.

What am I missing?

Here is some part of the code:

public class AddRendering : Sitecore.Shell.Applications.WebEdit.Commands.AddRendering
{
    protected new static void Run(ClientPipelineArgs args)
    {
        ...
        GetRenderingDatasourceArgs renderingDatasourceArgs = new GetRenderingDatasourceArgs(itemNotNull)
        {
            ContextItemPath = args.Parameters["contextitempath"],
            ContentLanguage = WebEditUtil.GetClientContentLanguage()
        };

        CorePipeline.Run("getRenderingDatasource", (PipelineArgs)renderingDatasourceArgs);
    }
}

....

var customdatasourceroot = "/sitecore/content//*[@@templateid='{templateid}']";
if (!string.IsNullOrEmpty(customdatasourceroot))
{
    var obj = renderingDatasourceArgs.ContentDatabase.GetItem(renderingDatasourceArgs.ContextItemPath);
    if (obj != null)
    {
        var objarray = (Item[])null;
        objarray = obj.Axes.SelectItems(customdatasourceroot);

        if (objarray != null)
        {
            foreach (var item in objarray)
            {
                renderingDatasourceArgs.DatasourceRoot.Add(item);
            }
        }
    }
}

....

if (!string.IsNullOrEmpty(renderingDatasourceArgs.CurrentDatasource))
{
    Item obj = Client.ContentDatabase.GetItem(renderingDatasourceArgs.CurrentDatasource);
    WebEditResponse.Eval(FormattableString.Invariant(FormattableStringFactory.Create("Sitecore.PageModes.ChromeManager.handleMessage('chrome:placeholder:controladded', {{ id: '{0}', openProperties: {1}, dataSource: '{2}' }});", (object)itemNotNull.ID.Guid.ToString("N").ToUpperInvariant(), (object)flag.ToString().ToLowerInvariant(), (object)obj.ID.Guid.ToString("B").ToUpperInvariant())));
}

I want to display certain nodes from the tree so that user can select from different sites.

  • What is your requirement here? – Mahendra Shekhawat Jul 25 at 9:04
  • I want to display certain nodes from the tree so that user can select from different sites. – Tofu TheGreat Jul 25 at 9:08
0

When you use var obj = renderingDatasourceArgs.ContentDatabase.GetItem(renderingDatasourceArgs.ContextItemPath) you get the current context Item (data source).

Then, you call obj.Axes.SelectItems(customdatasourceroot) to apply your query.

Your query is good, the issue is that you are applying it on the current data source item axes. Axes are a kind of directional query. So basically you are looking for all [@@templateid='{templateid}'] below your current data source item.

To fix it you need to change the root item to something more high level on the hierarchy.

  • HA! yea you're right. facepalm – Tofu TheGreat Jul 25 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.