Skip to content

Templates

Menu author

Thanks to HOCON’s flexibility, you can extract any reusable fragment into a template - a single value, an object, a list, and so on. Templates can live inside the same menu file or in a separate file pulled in via include.

For example, in each of the bunch of menus the “Close menu” button has the same look and parameters. Lets create this button, but not outside of default items list. Example:

closeButton {
slot: 5
texture: "5a6787ba32564e7c2f3a0ce64498ecbb23b89845e5a66b5cec7736f729ed37"
name: "&cClose"
lore: "&7Click to close the menu"
click {
closeMenu: true
}
}

Since this item outside of items list, this is a template.

Now you can include this template in any place of the menu. For this, you need a special placeholder. This placeholder has format:

${<template_name>}

Replace <template_name> to name of the your template block. In our case this is a closeButton. Lets add this template to the items list:

items: [
${closeButton}
]

Now after plugin reload, this item will appear in menu.

Note that the path to a template always begins from the file’s root, no matter where you use the placeholder to include it. For example, if you have a template inside another block:

templates {
items {
closeButton {
slot: 5
texture: "5a6787ba32564e7c2f3a0ce64498ecbb23b89845e5a66b5cec7736f729ed37"
name: "&cClose"
lore: "&7Click to close the menu"
click {
closeMenu: true
}
}
}
}

Then, if templates block placed in file’s root (doesn’t has parent blocks), placeholder to include closeButton block will be like this:

${templates.items.closeButton}

The main feature of templates if that you can use them multiple times. But our button template has static slot. To change slot we need to override it in place where we include it.

To override our object, we need to use this syntax:

items: [
${closeButton} {
slot: 0
}
]

After template placeholder we opened brackets as in default object. And then added item properties as always.

You can add or override any exists properties:

items: [
${closeButton} {
slot: 0
name: "Peter"
glow: true
}
]

To override list, you need to use similar syntax. For example, we need to set background for menu:

// Menu's items list
items: ${myTmpl} [
${closeButton} {
slot: 0
}
]
// Template
myTmpl: [
{
slot: "0-53"
material: STAINED_GLASS_PANE
name: " "
}
]

Templates in shared file useful to reuse your templates in multiple menus.

In order to tell the plugin that file is a templates file, you have to specify #invisible tag in the first line, otherwise your templates file will be detected by the plugin as a menu file and will produce error.

Below is an example of shared template file:

#invisible
btnClose {
texture: "5a6787ba32564e7c2f3a0ce64498ecbb23b89845e5a66b5cec7736f729ed37"
name: "&cClose"
click {
closeMenu: true
}
}
btnBack {
material: ARROW
name: "&cBack"
}

To use this templates you need to include this file inside menu file. For this, you need to use this command:

include required(file("./plugins/AbstractMenus/menus/<path_to_file>"))

You need to replace <path_to_file> to full path to your template file begins from menus folder.

In our case, templates file placed in the root of menus folder. Then menu file will looks like this:

include required(file("./plugins/AbstractMenus/menus/templates.conf"))
title: "Menu title"
size: 6
items: [
{
slot: 0
material: STONE
name: "Some item"
},
${btnClose} { slot: 1 }
]