Sites are the root node for your Pages and Posts and can be mapped against a specific
hostname
orsubdomain
. You can have several sites that will all have their own unique hierarchical content structure, but you need at least one site available.
Sites differ a bit from Pages and Posts in the sense that each site has both an object holding the metadata for the site and and optional object for global site content. The site content can, for example, be used to store header or footer information for your site.
When you start your Piranha application a site is automatically created for you with the name Default Site if there are no sites available. This site is only created on startup if there are no sites available, which means that after it has been created you can change the name to something different if desired.
Many calls to the Piranha Api
accept a Site Id as an optional parameter. If this parameter is omitted the default site will be used. Please note that if you have more than one site in your application you can choose which one should be the default site.
Let's take a look at how a simple Site Type could look like with a single region holding the Site Logo.
using Piranha.AttributeBuilder;
using Piranha.Extend;
using Piranha.Extend.Fields;
using Piranha.Models;
[SiteType(Title = "Simple Site")]
public class SimpleSite : SiteContent<SimpleSite>
{
[Region]
public ImageField Logo { get; set; }
}
To import this site type during application startup, add the following lines to your Configure
method.
using Piranha.AttributeBuilder;
var builder = new ContentTypeBuilder(api)
.AddType(typeof(SimpleSite));
builder.Build();
You can also define a single import for all of the content types in your application by adding the assemblies containing your types. The benefit of this is that you don't have to update your Startup code when adding new types.
using Piranha.AttributeBuilder;
var builder = new ContentTypeBuilder(api)
.AddAssembly(typeof(Startup).Assembly);
builder.Build();
The SiteTypeAttribute
has the following attributes available for configuring the behavior of the Site Type.
[SiteType(Title = "Simple Site")]
The display title to show when working with sites in the manager interface. If this property is omitted the class name of the Site Type will be used as the title.
Once your site type is imported into your application you can click on the site name in the manager, select your site type from the available dropdown and click save. After this is done you have access to the regions you have defined when editing your site.
Now that you know the basics for setting up sites, you should continue to read about the different components available for creating more advanced content. Information about this can be found in the articles Regions and Fields.