# Singletons vs Regions

**URL:** <https://discourse.getcockpit.com/t/singletons-vs-regions/316>\
**Category:** Support\
**Created:** [October 5, 2018, 10:06am UTC](https://discourse.getcockpit.com/t/singletons-vs-regions/316 "2018-10-05T10:06:53Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![WebShapedBiz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/webshapedbiz/32/123_2.png) [@WebShapedBiz](https://discourse.getcockpit.com/u/WebShapedBiz)\
**Post date:** [October 5, 2018, 10:06am UTC](https://discourse.getcockpit.com/t/singletons-vs-regions/316/1 "2018-10-05T10:06:53Z")

</div>

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ć

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [October 7, 2018, 8:26am UTC](https://discourse.getcockpit.com/t/singletons-vs-regions/316/2 "2018-10-07T08:26:02Z")

</div>

> [@Difference between Singleton and Region](https://discourse.getcockpit.com/t/difference-between-singleton-and-region/47):
>
> Hi, maybe a silly question but what is the difference between singleton and region? Thx slight_smile BTW cockpit is really great!

> [@Difference between Singleton and Region](https://discourse.getcockpit.com/t/difference-between-singleton-and-region/47/2):
>
> Singletons will replace regions. While looking back on past projects I investigated that regions where postly used like “single item” collections (e.g. for global configuration etc). the template feature was pretty useless as most of the time the rendering was on the client side. so regions will get removed from the core and will get replaced by “Singletons”.

* * *

btw now there is an official addon that brings backs regions: [GitHub - agentejo/Regions: Regions addon for Cockpit CMS](https://github.com/agentejo/Regions)

---

<div class="post-metadata">

**Author:** ![WebShapedBiz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/webshapedbiz/32/123_2.png) [@WebShapedBiz](https://discourse.getcockpit.com/u/WebShapedBiz)\
**Post date:** [October 7, 2018, 8:42am UTC](https://discourse.getcockpit.com/t/singletons-vs-regions/316/3 "2018-10-07T08:42:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [October 7, 2018, 8:45am UTC](https://discourse.getcockpit.com/t/singletons-vs-regions/316/4 "2018-10-07T08:45:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![WebShapedBiz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/webshapedbiz/32/123_2.png) [@WebShapedBiz](https://discourse.getcockpit.com/u/WebShapedBiz)\
**Post date:** [October 8, 2018, 5:49am UTC](https://discourse.getcockpit.com/t/singletons-vs-regions/316/5 "2018-10-08T05:49:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [October 14, 2018, 3:16pm UTC](https://discourse.getcockpit.com/t/singletons-vs-regions/316/6 "2018-10-14T15:16:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)\
**Post date:** [October 16, 2018, 1:10pm UTC](https://discourse.getcockpit.com/t/singletons-vs-regions/316/7 "2018-10-16T13:10:55Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![WebShapedBiz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/webshapedbiz/32/123_2.png) [@WebShapedBiz](https://discourse.getcockpit.com/u/WebShapedBiz)\
**Post date:** [October 16, 2018, 1:25pm UTC](https://discourse.getcockpit.com/t/singletons-vs-regions/316/8 "2018-10-16T13:25:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nilsborg](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/nilsborg/32/138_2.png) [@nilsborg](https://discourse.getcockpit.com/u/nilsborg)\
**Post date:** [October 19, 2018, 1:01pm UTC](https://discourse.getcockpit.com/t/singletons-vs-regions/316/9 "2018-10-19T13:01:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pauloamgomes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/pauloamgomes/32/48_2.png) [@pauloamgomes](https://discourse.getcockpit.com/u/pauloamgomes)\
**Post date:** [October 19, 2018, 2:51pm UTC](https://discourse.getcockpit.com/t/singletons-vs-regions/316/10 "2018-10-19T14:51:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![russellfeeed](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/russellfeeed/32/110_2.png) [@russellfeeed](https://discourse.getcockpit.com/u/russellfeeed)\
**Post date:** [May 27, 2021, 4:25pm UTC](https://discourse.getcockpit.com/t/singletons-vs-regions/316/11 "2021-05-27T16:25:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![russellfeeed](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/russellfeeed/32/110_2.png) [@russellfeeed](https://discourse.getcockpit.com/u/russellfeeed)\
**Post date:** [June 7, 2021, 9:42am UTC](https://discourse.getcockpit.com/t/singletons-vs-regions/316/12 "2021-06-07T09:42:50Z")

</div>

Nevermind it seems to be working now
