Back to topic list

Globalizer

Globalizer links parts of contexts to other parts by refencing them with '@@' before the object path

Example

we have children:

{
    children: [
        {
            name: 'Samuel'
            favorite_toy: 'Mindstorms'
        },
        {
            name: 'Tim'
            favorite_toy: 'Duplo'
        },
    ]
}

and we have toys:

{
    toys: {
        mindstorms: {
            website: 'http://www.lego.com/en-us/mindstorms'
        },
        duplo: {
            website: 'http://www.lego.com/en-us/duplo'
        }
    }
}

globalizer offers a way to connect these two entities.

{
    children: [
        {
            name: 'Samuel',
            favorite_toy: '@@toys.mindstorms'
        },
        {
            name: 'Tim',
            favorite_toy: '@@toys.duplo'
        },
    ]
}

Now we can comfortably access website of the toy by:

{{favorite_toy.website}}

Not only that, the non-technical person administering the content will be able to just pick from available options:

gif showing globalizer

Chaining globalizers

You can chain as many globalizers as you want. For example, you can do this:

{
    children: {
        samuel: {
            name: 'Samuel',
            favorite_toy: '@@global.toys.mindstorms'
        },
        tim: {
            name: 'Tim',
            favorite_toy: '@@global.toys.duplo'
        },
    },
    toys: {
        mindstorms: {
            website: 'http://www.lego.com/en-us/mindstorms',
            store: '@@global.shops.toyrus'
        },
        duplo: {
            website: 'http://www.lego.com/en-us/duplo'
        }
    },
    shops: {
        toyrus: {
            has_parking: true
        }
    }
}

Now you can find out if the store where Samuel's favorite toy is sold has parking by:

    {{global.children.samuel.favorite_toy.store.large}}

Shallow globalizer

To circumvent having a circular globalizer you can use special shallow globalizer using !@ prefix. This will not go deeper than the first link.

Limitations

One current limitation is that you can't make deep circular links

{
    toys: {
        mindstorms: {
            website: 'http://www.lego.com/en-us/mindstorms',
            favorite_child: '@@global.children'
        },
        duplo: {
            website: 'http://www.lego.com/en-us/duplo'
        }
    },
    children: {
        samuel: {
            name: 'Samuel',
            favorite_toy: '@@global.toys.mindstorms'
        },
        tim: {
            name: 'Tim',
            favorite_toy: '@@global.toys.duplo'
        },
    }
}
Back to topic list

Shout out to pexels and freepik