This project is read-only.

Any tutorials on using Taxonomies programatically?

Topics: General, Troubleshooting, Writing modules
Mar 23, 2013 at 8:07 PM
Edited Mar 23, 2013 at 8:08 PM
I am wanting to create some front-end pages to collect info from site visitors. Some of the inputs would include checkbox lists, drop downs or radio buttons. I've looked over the Creating Relations documentation, but this seems a little bit much for my scenario of collecting low-level data.

I've read some discussions about creating taxonomies in migrations, and have looked at the implementation used in some modules (Pluralsight.Movies, for example). However, most everything seems to use Records/Parts and I was just thinking of low-level data collection and only using Records.

Anyways, I'm just a bit confused about how I might programatically add it to my page, particularly since I am not using a part. All the examples I see use "ContentDefinitionManager.AlterPartDefinition" in the migration file.

Say I have a simple Record.cs file with FirstName, LastName (among others). Then I created a taxonomy of Interests (Hiking, Fishing, Bicycling, etc.) using migrations.

In my view for that I would do this:
@Html.TextBoxFor(m => m.FirstName)
@Html.TextBoxFor(m => m.LastName)
But how do I insert the checkboxes for Interests? I thought I could encapsulate it in a shape and then call @Display.TaxonomyInterest so that I can have some code inside to customize how I want it to look.

I know I can do something like this to create a shape in my controller:
public ShapeResult MyShape()
            var shape = _orchardServices.New.MyShape();
            return new ShapeResult(this, shape);
and then call something like this in my view (and have the corresponding .cshtml file):
Well, that's a lot to chew on I guess. But is there something out there I can read through to help me figure out the best way to use taxonomies to display checkbox lists, radio buttons or drop downs in the front end?

Mar 27, 2013 at 11:45 PM
If you're asking the best way to use taxonomies, I think it would be to create a custom content type, e.g. Person, and attach a TaxonomyField to it (configured to use your Interests taxonomy).

If you simply want to render a taxonomy without using the TaxonomyFieldDriver, you will probably have to do a lot yourself. I don't know if there are any tutorials on that, but if you look at the source code of Taxonomies you'll see how it works.
Apr 16, 2013 at 7:51 PM
Pluralsight's "Advanced Orchard" tutorial has a nice intro to Taxonomies in code.