i found a lot of inromation on how to create a datatype and already created a few. I was wondering which is the best prectice to store daa when your datatype has multiple input controls (something let's say, like the Image Cropper data type)
I created this one where i had 2 dropdownlists and 3 text boxes. What i did was before save concatenate the values sepated with commas, on read, split the values and populate each control.
it works pretty well, just would like to know if somebody else could tell me how they do it and if is there a best practice or something.
storing the values in some kind of a custom separated list isn't the worst thing as long as the stored items are quite simple and there is a flat hierarchy. The best approach here would be to write your own custom data type which is not a usercontrol wrapper, as described here: http://www.nibble.be/?p=50. This way you can control what is stored in the database, so ideally you would save this as xml which can then be used directly in your XSLT scripts. The related links data type does exactly this for instance.
Another way, albeit a hacky one, would be to generate the XML to be stored in the usercontrol anyway and save the string in the umbracoValue. However, this will NOT create proper XML nodes to be used out of the box in the XSLT scripts as the engine will put the content in a CDATA section. The trick to convert it back to proper XML is to read it with .Net and return a proper XPathNodeIterator. Works, and I can provide you with the code to convert it back if you like, yet it turned out that it is much simpler to create your own 'proper' datatype as outlined in the link above.
That's it to my knowledge, keen to hear if somebody has come up with something completely different.
Creating a data type with multiple controls
i found a lot of inromation on how to create a datatype and already created a few.
I was wondering which is the best prectice to store daa when your datatype has multiple input controls (something let's say, like the Image Cropper data type)
I created this one where i had 2 dropdownlists and 3 text boxes.
What i did was before save concatenate the values sepated with commas, on read, split the values and populate each control.
it works pretty well, just would like to know if somebody else could tell me how they do it and if is there a best practice or something.
Hiya,
storing the values in some kind of a custom separated list isn't the worst thing as long as the stored items are quite simple and there is a flat hierarchy. The best approach here would be to write your own custom data type which is not a usercontrol wrapper, as described here: http://www.nibble.be/?p=50. This way you can control what is stored in the database, so ideally you would save this as xml which can then be used directly in your XSLT scripts. The related links data type does exactly this for instance.
Another way, albeit a hacky one, would be to generate the XML to be stored in the usercontrol anyway and save the string in the umbracoValue. However, this will NOT create proper XML nodes to be used out of the box in the XSLT scripts as the engine will put the content in a CDATA section. The trick to convert it back to proper XML is to read it with .Net and return a proper XPathNodeIterator. Works, and I can provide you with the code to convert it back if you like, yet it turned out that it is much simpler to create your own 'proper' datatype as outlined in the link above.
That's it to my knowledge, keen to hear if somebody has come up with something completely different.
Sascha
is working on a reply...