Developer forum

Forum » CMS - Standard features » Reading ItemType properties from the .xml

Reading ItemType properties from the .xml

Kevin O''Driscoll
Reply

Hi, I was wondering if there is a DW way to read properies or settings from an ItemType XML. For example we have different product types which have applied different filter settings. I want to create a filter Custom Module that will dynamically create the filter controls dependent on the product type (ItemType) being requested. Some sample code below from the ItemType.

It would need to search the XML for <options sourceType="Static"> or similar and return the Static option(s) with the <field name=""

Sample code:

      <field name="Age Suitability" systemName="Age_Suitability" description="Choose age ranges suitable for this Product" type="System.Collections.Generic.IEnumerable`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib">
        <editor type="Dynamicweb.Content.Items.Editors.CheckboxListEditor`1, Dynamicweb">
          <editorConfuguration />
        </editor>
        <validators>
          <validator type="Dynamicweb.Content.Items.Editors.RequiredValidator, Dynamicweb" errorMessage="" />
        </validators>
        <options sourceType="Static">
          <Static>
            <option name="7-10 year olds" value="7-10" />
            <option name="10-13 year olds" value="10-13" />
            <option name="13-16 year olds" value="13-16" />
            <option name="9-13 year olds" value="9-13" />
            <option name="13-17 year olds" value="13-17" />
          </Static>
        </options>
      </field>
      <field name="Product Filter" systemName="Product_Filter" description="Add a filter for your holiday" type="System.Collections.Generic.IEnumerable`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib">
        <editor type="Dynamicweb.Content.Items.Editors.CheckboxListEditor`1, Dynamicweb">
          <editorConfuguration />
        </editor>
        <options sourceType="Static">
          <Static>
            <option name="UK Holiday" value="UKOnly" />
            <option name="Overseas Holiday" value="OverseasOnly" />
          </Static>
        </options>
      </field>

 

Hope you can help


Replies

 
Morten Bengtson
Reply

Hi Kevin,

You can access the item type metadata (ItemType_*.xml) by using the API:

var fields = Dynamicweb.Content.Items.ItemManager.Metadata.GetItemFields("MyItemType");

foreach (var field in fields)
{
    var options = field.Options.Values;

    foreach (var option in options)
    {
        var name = option.Name;
        var value = option.Value;
    }
}

 

You must be logged in to post in the forum