How to handle same Resource but has different Resource ID's across web environments(e.g. local, dev, staging, live)


I was wondering how people handle different ID’s across different environments, for instance let say am displaying a list of items using the extra get resource.

[[!getResources? &parents=`5` &limit=`5` &tpl=`blogPost` &includeContent=`1`]]

Here the parent id is 5, however that same resource maybe parent id 6 on dev or parent id 7 on staging.

So unless the databases across severs have same ID’s for each resource than it work, just wondered how people handled it when the resources are different across servers?


You could store the parent id in a system setting in each environment (ClientConfig will give you the same result).

You would then reference it in your call like this:

// [[++parent_id]] being the key that stores the parent ids
[[!getResources? &parents=`[[++parent_id]]` &limit=`5` &tpl=`blogPost` &includeContent=`1`]]

This is excellent idea, thanks will give that a go :grinning:

I try to keep things using the same ID. :wink:

Gitify helps there. It builds file representations of your database objects (like resources) that you can deploy to different environments and build there. It also includes some basic ID conflict resolution, so as long you keep things reasonably in sync it that usually resolves those cleanly.

Rather than hardcoding IDs in your template, you can also try using “relative” IDs. For example to list children of the current resource, you can use &parents=`[[*id]]` . Or &parents=`[[*parent]]` for things one directory up. That obviously doesn’t help if you want to show blog items in a generic sidebar across different sections, in which case creating settings (with clientconfig or just regular settings) is useful.

Interesting method will check that out too