You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are implementing Piranha CMS to be used as a headless CMS and provide content for our eshop website. I was trying to find a way to create lists of any content that can be created in a single place at the Manager and can be used by any page in any site. An example of this is a content type list of Banners which can be created once and can be used in our homepage and also in some other pages. I couldn't find any documented way to implement this or how to create content type groups and content type lists so i'm creating this Q&A to help anyone else who is in the same place and also my forgetful future self.
[ContentType(Title ="Banner", UseExcerpt =false, UsePrimaryImage =false)]publicclassBannerContent:Banner<BannerContent>{[Region(Title ="Content", Display = RegionDisplayMode.Content)]publicBannerContentRegionContent{get;set;}publicclassBannerContentRegion{[Field(Title ="Desktop Image", Options = FieldOption.HalfWidth)]publicImageFieldImage{get;set;}[Field(Options = FieldOption.HalfWidth, Placeholder ="Label for the call to action link", Title ="CTA Label")]publicStringFieldCTALabel{get;set;}[Field(Options = FieldOption.HalfWidth, Placeholder ="Action link href. Must be an absolute link", Title ="CTA URL")]publicStringFieldCTAUrl{get;set;}}}}
Created a new Content Item
publicclassBannerItem{// The id of the pagepublicGuidId{get;set;}// The modelpublicBannerContent?Content{get;set;}// Gets a single item with the provided id using the// injected services you specify.staticasyncTask<BannerItem>GetById(stringid,IApiapi){varbanner=await api.Content.GetByIdAsync<BannerContent>(new Guid(id));returnnew BannerItem {Id=new Guid(id),Content=banner};}// Gets all of the available items to choose from using// the injected services you specify.staticasyncTask<IEnumerable<DataSelectFieldItem>>GetList(IApiapi){varbanners=await api.Content.GetAllAsync<BannerContent>();return banners.Select(p =>new DataSelectFieldItem {Id= p.Id.ToString(),Name= p.Title});}}
Create a new Block with a DataSelectField of the new type (the secret sauce)
That way we provide the user a new Content type (of type Banner) on the sidebar where they can create a list of banners (or any other content which inherits the same Content Group).
Then, we have a new BlockGroup (inside of the "Content List" category as set at the BlockGroup attributes) available on any page where we can select and sort any content of the specific type.
Inside that BlockGroup we can select the previously created content item and also sort them accordingly.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
We are implementing Piranha CMS to be used as a headless CMS and provide content for our eshop website. I was trying to find a way to create lists of any content that can be created in a single place at the Manager and can be used by any page in any site. An example of this is a content type list of Banners which can be created once and can be used in our homepage and also in some other pages. I couldn't find any documented way to implement this or how to create content type groups and content type lists so i'm creating this Q&A to help anyone else who is in the same place and also my forgetful future self.
The way we did it is by:
That way we provide the user a new Content type (of type Banner) on the sidebar where they can create a list of banners (or any other content which inherits the same Content Group).
Then, we have a new BlockGroup (inside of the "Content List" category as set at the BlockGroup attributes) available on any page where we can select and sort any content of the specific type.
Inside that BlockGroup we can select the previously created content item and also sort them accordingly.
Beta Was this translation helpful? Give feedback.
All reactions