Documentation > CMS Template API Library > Asset > GetPanelsFromFolder(Asset,String,AssetParams,AssetType,String,String)

GetPanelsFromFolder

Used for navigation lists. Panels are initialized using children of the first argument "folder" asset instance, which must be a folder. Data from the panels is stored on "this" asset. This could be used, to store the order of the list or to associate other metadata such as enabled, disabled. If there is more than one child from the same branch, the asset with the highest asset id is returned. Assets are bound to the panels by branch id unless the optional idName parameter is specified The optional idName and labelName parameters are for backward-compatibility with navigation panels stored with the old API. If an idName is specified, then the assets are bound to the panels by asset id instead of the branch id. It is not necessary to add hidden fields with the id or branch id to the form, they are automatically generated. If using this method to initialize an input panel, additional code is required on the post_input.aspx template to copy the data from the current asset to the folder (or other asset where you are storing the metadata), unless you are storing the data on the current asset that you are editing.

public List<AssetPanelEntry> GetPanelsFromFolder(Asset,String,AssetParams,AssetType,String,String)


Returns

A List of AssetPanelEntry objects

Parameters

NameDescriptionType
folder The folder whose children we will use to initialize the list CrownPeak.CMSAPI.Asset
panelName The name of the panel System.String
assetParams Optional:Used like in GetFileList or GetFolderList to filter data, etc. CrownPeak.CMSAPI.AssetParams
type Optional:Can be used to get back only a specific type of child - file or folder, defaults to AssetType.Unspecified which returns both CrownPeak.CMSAPI.AssetType
labelName Optional:The string that will be used to store the folder's label when we store the panel data. Use lower case. Defaults to panelName + ".label" System.String
idName Optional:The string that will be used to store the folder's id when we store the panel data. Use lower case. Defaults to panelName + ".id" System.String

Code Example

C#

Sample:
<%

// output example
List<AssetPanelEntry> panels = asset.GetPanelsFromFolder(asset.Parent, "folder_list");

foreach(AssetPanelEntry panel in panels)
{
  Out.WriteLine("id=\"{0}\", Name=\"{1}\"<br/>", panel["folder_list.id"], panel["folder_list.label"]);
  Out.WriteLine("Type: {0}<br/>", panel.ChildAsset.Type);
}

//input example
List<AssetPanelEntry> panels2 = asset.GetPanelsFromFolder(asset.Parent, "folder_list");

AssetPanelEntry currentPanel;
while(Input.NextPanel(panels2, out currentPanel))
{
  Input.ShowTextBox("Name", "folder_list.label");
  Out.WriteLine("Type: {0}<br/>", currentPanel.ChildAsset.Type);
}

//Exclude Retired and Archived Assets
AssetParams assetParams = new AssetParams();
assetParams.ExcludeFilterStatus = Util.MakeList("Archived", "Retired");
List<AssetPanelEntry> panels2 = asset.GetPanelsFromFolder(asset.Parent, "folder_list", assetParams);

// Examples where you specify your own labelName and idName
// output example
List<AssetPanelEntry> panels = asset.GetPanelsFromFolder(asset.Parent, "folder_list", labelName: "folder_label", idName: "folder_id");

foreach(AssetPanelEntry panel in panels)
{
  Out.WriteLine("id=\"{0}\", Name=\"{1}\"<br/>", panel["folder_id"], panel["folder_label"]);
  Out.WriteLine("Type: {0}<br/>", panel.ChildAsset.Type);
}
            
//input example
List<AssetPanelEntry> panels2 = asset.GetPanelsFromFolder(asset.Parent, "folder_list", labelName: "folder_label", idName: "folder_id");

AssetPanelEntry currentPanel;
while(Input.NextPanel(panels2, out currentPanel))
{
  Input.ShowTextBox("Name", "folder_label");
  Out.WriteLine("Type: {0}<br/>", currentPanel.ChildAsset.Type);
}
            
//post_input example - if the asset instance you are using to call GetPanelsFromFolder is not the same as the asset you are editing.

Asset folder = asset.Parent;
string prefix = "folder_" ;// Use a string common to your panel name, idname, and label name.  If you used the version were you DID NOT specify your own label name and idname, the panel name should work.
Dictionary<string, string> allContent = folder.GetContent();
foreach(KeyValuePair<string, string> entry  in allContent)
{
  if (entry.Key.StartsWith(prefix))
  {
    folder.DeleteContentField(entry.Key);
  }
}

Dictionary<string, string> toFolder = new Dictionary<string, string>();
foreach(KeyValuePair<string, string> entry  in context.InputForm)
{
  if (entry.Key.StartsWith(prefix))
  {
    toFolder.Add(entry.Key, entry.Value);
  }
}
context.InputForm.Remove(toFolder.Keys);
folder.SaveContent(toFolder);

%>

Connect with Crownpeak