Content Type Meta Fields
Content types vary quite a lot, but it's often useful to get a general use name, description or other field. For example, the "Title" of a Page makes sense as its title - as does the "Username" of a User. By default, Socialstack will guess at an appropriate field for use as a meta title field, and similarly for a description field, based on if a content type has any of a series of common field names.
Getting a meta value
Use the GetMetaFieldValue method on an autoService to read a named meta field. This is context aware, so it's possible to return different values based on the role if necessary:
// Get a service:
var service = Services.GetByContentType(anUnknownContentObject.Type);
// Read the title:
var title = await service.GetMetaFieldValue(context, "title", anUnknownContentObject);
// If anUnknownContentObject was a page, the returned title would be the same as page.Title
Automatic field values
If you have a field with any of the following names, it will be used as the meta field of the given name. It will favour fields closer to the start of the list if you have more than one. Case doesn't matter.
- title: "fullname", "username", "firstname", "title", "name", "url"
- description: "description", "shortdescription", "bio", "biography", "about"
Specifying which fields to use
If you're making a content type and you want a particular field to be the field used when the meta title is requested and it isn't in the automatic list above, mark the field with the Meta attribute like so:
[Meta("title")]
public string FancyTitle;
Open Graph
A common use case of metadata is the meta tags on a page, with some well defined ones used by search engines. The Api/OpenGraphTags module adds, for example, og:title to a page where the value originates from this content type meta API.
Keyword Metadata
The Api/PageMetadata module can also be added and will expose any page and 'primary object' tags into the page header keywords metadata