Singletons vs Regions

Hi.

I was using Cockpit several years ago, even provided and maintained an HR language file, and I remember using the Regions as snippets, for example, the site navigation menu.

Returning back to see what’s new, I discovered the Singletons introduction as the replacement for Regions but I cannot figure out how to use Singletons for the same example, the site navigation menu.

Any help would be appreciated.

Cheers,
Siniša Perović


btw now there is an official addon that brings backs regions: GitHub - agentejo/Regions: Regions addon for Cockpit CMS

2 Likes

Thank you @serjoscha87, I’ve read all of that but missed to find out where is the gain in having singletons over regions. Must dig deeper.

Cheers.

Hm. For me Artur’s posts says it all. So what precisely are you missing in that explanation?

Thank you @serjoscha87 for your time and effort here. I’m not newbie but not the professional either so bare with me please.

Well, as I wrote in my post, I remember using “old” Regions as snippets (like nav bar or footer). The name and code was all you need to create one.
The Singleton and “new” Region are the form builders. The “new” Region gives me Template where I can create my Snippets (although I don’t get why I need form to get it populated) and the Singleton is basically the same but without the Template.
Could you be so kind and give me few examples of intended use for both Singleton and “new” Region.

Thank you again for your time and effort.

I’m afraid I am not able to give you some examples - I usually don’t use singletons and same with the regions back in the days. But I guess you are right - the main differnce is just that the template thingy fell away.
Guess thats all.

So basically now I think a collection is just a bunch of singletons.

@WebShapedBiz, think you can use singletons as basic structures of information that are not repeating, for example, let’s imagine you want to be able to configure the footer of your website, maybe you can have a singleton with a bunch of fields:

Footer Links
Copyright Message

Now let’s imagine you want to store your site generic settings, you can have a singleton “settings” and store things like:

Site Name
Default homepage
Site Logan
Site Logo
Global Metatags
etc…

The difference to regions is already clarified by @serjoscha87, the addon now is irrelevant and its there only for legacy purposes.

Hope that helps.

Thank you @pauloamgomes @serjoscha87 for your support. I managed to wrap my head around it. The form part was confusing for me, it seemed like an unnecessary overhead to the whole “snippet” concept but I can live with it.

Cheers.

1 Like

Helloo!

I’m starting to get the concept as well. But for a bit more concrete advice:

When I update my Cockpit instance from 0.7.0 to the latest version and already have a bunch of content in the database … uhm … can I convert regions to singletons?

You can still use regions (just install the regions addon), to convert you may need to write a migration script, seems nothing too much complicated.

Hi all
Here’s my use case for Regions.

Region Template was used to return HTML but also run PHP. The PHP could use GET params passed in and so dynamically build the HTML and return it.
Regions basically provided me with a microservice architecture

e.g. api/regions/get/calcsum?value1=10&value2=20

‘calcum’ Region template

<?php $sum = $_GET['value1'] + $_GET['value2']; echo "

The Total is $sum</h1"; The legacy Region module is giving me an error when I add <?php in the template

Nevermind it seems to be working now