> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Templates

> Run the template gallery on a Kubernetes deployment.

The template gallery runs in the **web** service (the `template-gallery` module) of every Ayakaleaf Pro pod; the **filestore** service in the same pod stores the template files and renders their previews. Categories, permissions and publishing are described in [Templates](https://ayakaleaf-pro.mintlify.site/on-premises/configuration/overleaf-toolkit/templates.md).

| | |
| - | - |
| Services | web (`template-gallery` module), filestore (files and preview images) |
| Stored data | template metadata in MongoDB; ZIP, PDF and preview images in filestore's template store: `/var/lib/overleaf/data/template_files` on the data volume, or the S3 bucket `OVERLEAF_FILESTORE_TEMPLATE_FILES_BUCKET_NAME` |
| Pod → outside | none (S3, if used) |
| Periodic jobs | none: previews are rendered the first time they are viewed |

### Configuration

**1. ConfigMap**

```yaml title="30-config.yaml (additions)" wrap theme={null}
  OVERLEAF_TEMPLATE_GALLERY: "true"
  ENABLE_CONVERSIONS: "true"
  OVERLEAF_TEMPLATE_CATEGORIES: academic-journal book presentation poster cv report thesis
  TEMPLATE_ACADEMIC_JOURNAL_NAME: Journal articles
  TEMPLATE_ACADEMIC_JOURNAL_DESCRIPTION: Templates for academic journal submissions.
  # ... one _NAME and _DESCRIPTION per category, see the Toolkit page
```

**2. A templates user (optional)**

Admins can always publish. To let a non-admin user manage the gallery, create the user, read its ID from MongoDB and put it into the ConfigMap:

```bash wrap theme={null}
kubectl -n overleaf exec mongo-0 -- mongosh --quiet \
  'mongodb://mongo-0.mongo:27017,mongo-1.mongo:27017,mongo-2.mongo:27017/sharelatex?replicaSet=overleaf' \
  --eval 'db.users.findOne({ email: "templates@example.com" })._id.toString()'
```

```yaml theme={null}
  OVERLEAF_TEMPLATES_USER_ID: "<the ID printed above>"
```

**3. Apply and restart**

```bash theme={null}
kubectl apply -f 30-config.yaml
kubectl -n overleaf rollout restart deployment/overleaf     # or statefulset/overleaf
```

### Several replicas

* The template files must be in S3: with files on each replica's own disk, every node would show a different gallery. The [Horizontal scaling](https://ayakaleaf-pro.mintlify.site/on-premises/configuration/kubernetes/horizontal-scaling.md) setup already uses the bucket `overleaf-template-files`.
* Publishing takes the PDF of the project's last compile, which exists only on the replica that compiled it. The load balancer's sticky cookie keeps a user on that replica, so publish from the same browser session that compiled.

### Tested on Kubernetes

On Kubernetes 1.37 with three replicas behind HAProxy and the template files in the S3 bucket `overleaf-template-files` (Garage), our end-to-end tests for the template gallery pass (41 cases): publishing a compiled project from the File menu and the PDF, preview images and source ZIP served from the bucket; creating projects from a template; categories, search, sorting and pages of the gallery; editing, overwriting and deleting templates; permissions of admins, regular users and the templates user from `OVERLEAF_TEMPLATES_USER_ID` (its ID read from MongoDB as described above); and malformed requests.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.