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

GetPanelsFromFolder

Used for navigation lists. Panels are initialized using children of "this" asset instance or this instances parent, if this is a file. 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 This method is overloaded. This version would be the most common case where the metadata is stored on the same folder whose children we are using to initialize the list. 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. The other version would allow you to save the metadata on a different asset such as the current asset. 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.

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


Returns

A List of AssetPanelEntry objects

Parameters

NameDescriptionType
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("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("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("folder_list", assetParams);
 
 // Examples where you specify your own labelName and idName
 // output example
 List<AssetPanelEntry> panels = asset.Parent.GetPanelsFromFolder( "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.Parent.GetPanelsFromFolder( "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
 
 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