The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]
Generic Content module is a module for managing content items. We can specify arbitrarily number of additional data (in Sitefinity called meta data) to each content. So, for example, the base implementation of Generic Content module has following data in addition to the content itself:
Persistence and several other things, however, are automatically handled by Sitefinity making this whole process a rather simple task.
Let us now examine the meta field declaration for the sample products module:
<add key="Products.Name" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="Name this content" mandatory="True" /> |
<add key="Products.Price" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="" /> |
<add key="Products.SKU" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="" /> |
<add key="Products.Weight" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="" /> |
<add key="Products.Category" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="" /> |
The actual syntax of the meta field element can be described as following:
The process for defining meta fields user interface is identical for both inserting and editing content, so we will explain it only on the sample for inserting content.
In the template for ProductEditView view, we should locate the ContentMetaFields control and inside of it we need to place a control which implements ITextControl interface (TextBox, DropDownList…) and make sure that the ID of the control is same as the key of the metafield for which the control is being defined. In practice, this means that our code would look something like this:
<sf:ContentMetaFields id="MetaFields" runat="server"> |
<ItemTemplate> |
… |
<asp:TextBox ID="Price" runat="server"></asp:TextBox> |
… |
</ItemTemplate> |
</sf:ContentMetaFields> |
*** BEGIN NOTE ***
While it may seem at first that this approach would serve only very simple scenarios, the fact that Sitefinity works against ITextControl interface allows for very complex meta field editors. For example, one could create a user control, wrap RadEditor inside of it and implement ITextControl interface on it - thus providing rich text editor as a meta field editor.
*** END NOTE ***
All that one needs to do - in order to display the value of meta field - is to place ITextControl (e.g. Label) in the ContentView template and set the ID of the ITextControl same as the key of the meta field for which we wish to display the value.
For example, we could place following markup to display the weight of the product:
<asp:Label ID="Weight" runat="server"></asp:Label> |
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.