Nibble

Archive for the 'xml' Category


Storing parseable xml data in a datatype 6

As a follow up on the creating custom umbraco datatypes post I’ll show how to store parseable xml data in a datatype.

By default all propertry values get saved inside a cdata section(in the /data/umbraco.config file, wich has all published content).

Like in this example, a property with the alias test will look like this.

<data alias=”test”><![CDATA[1051;1052;1054]]></data>

But in some cases you would want to override this behavior, especially when you want to store xlm data.

Like the related links datatype in umbraco v4. This will store it’s links as child nodes of the data node.

<data alias=”links”>
        <links>
          <link title=”Same page” link=”http://www.google.com” type=”external” newwindow=”1″ />
          <link title=”Other page” link=”1051″ type=”internal” newwindow=”0″ />
        </links>
</data>

To do this the first step is to create a new class that inherits from umbraco.cms.businesslogic.datatype.DefaultData and overrides the ToXMl method.

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
 
namespace umbraco.editorControls.relatedlinks
{
    public class RelatedLinksData : umbraco.cms.businesslogic.datatype.DefaultData
    {
        public RelatedLinksData(umbraco.cms.businesslogic.datatype.BaseDataType DataType) : base(DataType) { }
 
        public override System.Xml.XmlNode ToXMl(System.Xml.XmlDocument data)
        {
            if (this.Value != null) {
                XmlDocument xd = new XmlDocument();
                xd.LoadXml(this.Value.ToString());
                return data.ImportNode(xd.DocumentElement, true);
            } else {
                return base.ToXMl(data);
            }
        }
 
    }
}

 

Final step is to alter the class that implements the umbraco.interfaces.IDataType interface (the one with the guid) so that the new class is used instead of the default one. So just change

public override umbraco.interfaces.IData Data
        {
            get
            {
                if (_baseData == null)
                    _baseData = new umbraco.cms.businesslogic.datatype.DefaultData(this);
                return _baseData;
            }
        }

   

To (depending on how the class is named, in this case it’s RelatedLinksData)

public override umbraco.interfaces.IData Data
        {
            get
            {
                if (_baseData == null)
                    _baseData = new RelatedLinksData(this);
                return _baseData;
            }
        }

Codegarden 08 - flash and umbraco 15

I’m back from Denmark and had an amazing week ! First with the retreat and then with codegarden08. For the people who couldn’t make it, you can download my flash and umbraco presentation below.

 

Untitled-1

Presentation: download pdf

Most importing part of the presentation was the release of a new umbraco package. NibbleFX (flash express).

In short: Have an xml driven flash movie you would like to manage with umbraco? This package will do all the work for you, just upload your xml file and documenttypes, templates, xslt and macro’s get created automaticly, you can even import the content.

Check out this screencast ( of a beta version) if you want to see a demo.

Untitled-2

NibbleFX: download

Enjoy ….

/Config/Dashboard.config 6

Just posted this on the forum and I thought I could do a quick post about the umbraco dashboard.config file.

When you log in the the umbraco backend or when you enter a section, the right side of the umbrao backend will be empty

image

You can fill up these ‘dashboards’ with tab pages that contain usercontrols.

How do you do this ? You will have to edit the /config/dashboard.config file.

Default the dashboard.config file looks like this:

<?xml version=”1.0″ encoding=”utf-8″ ?> 
<dashBoard>
<!–
    <section>
    <areas>
        <area>default</area>
        <area>content</area>
    </areas>
    <tab caption=”Last Edits”>
        <control>/usercontrols/dashboard/latestEdits.ascx</control>
    </tab>
    <tab caption=”Latest Items”>
        <control>/usercontrols/dashboard/newestItems.ascx</control>
    </tab>
    <tab caption=”Create blog post”>
        <control>/usercontrols/umbracoBlog/dashboardBlogPostCreate.ascx</control>
    </tab>
</section>
–>
</dashBoard>

 

So to add a usercontrol to th content area we should add this:

<?xml version=”1.0″ encoding=”utf-8″ ?> 
<dashBoard>
 
    <section>
    <areas>
        <area>content</area>
    </areas>
 
    <tab caption=”Last Edits”>
        <control>/usercontrols/mycustomusercontrol.ascx</control>
    </tab>
 
</section>
</dashBoard>