# Shared controllers?

**URL:** <https://forum.getkirby.com/t/shared-controllers/1112>\
**Category:** Questions\
**Tags:** v2\
**Created:** [May 19, 2015, 11:45am UTC](https://forum.getkirby.com/t/shared-controllers/1112 "2015-05-19T11:45:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [May 19, 2015, 11:45am UTC](https://forum.getkirby.com/t/shared-controllers/1112/1 "2015-05-19T11:45:22Z")

</div>

I have read about Kirby controllers. It’s nice to have functions attached to a template.

Are there any shared controllers? What I mean is a controller that are used by more than one template.

**An example:**

A function to be put, for example in a controller.

```
function widget() {
    echo 'Do this in my sidebar';
}

```

…used by…

```
/blog/a-post
/blog/a-post2
/home

```

Home and blog are different template files. I could duplicate code or have it in a plugin. Should I not use controllers for shared functions?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 19, 2015, 11:49am UTC](https://forum.getkirby.com/t/shared-controllers/1112/2 "2015-05-19T11:49:54Z")

</div>

A controller is always attached to a template by it’s name, so there is nothing like a shared controller. In that case I’d suggest to put those functions into a plugin.

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [August 18, 2015, 8:25am UTC](https://forum.getkirby.com/t/shared-controllers/1112/3 "2015-08-18T08:25:31Z")

</div>

A solution to the problem:

[http://forum.getkirby.com/t/shared-controller/1839](http://forum.getkirby.com/t/shared-controller/1839)

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:04pm UTC](https://forum.getkirby.com/t/shared-controllers/1112/4 "2025-02-06T17:04:32Z")

</div>

Archived on February 6, 2025, 5:04pm UTC


