Skip to content
  1. Extras
  2. VueTools
  3. API Composables

API Composables

Ready composables for MODX work from Vue components. Each is imported from its own Import Map key.

useLexicon

MODX lexicons.

javascript
import { useLexicon } from '@vuetools/useLexicon'

const { _, has, getByPrefix } = useLexicon()
MethodReturnsDescription
_(key, params?)stringLexicon value; falls back to key if missing
has(key)booleanWhether the key exists
getByPrefix(prefix)objectAll keys starting with prefix

params fills placeholders written as [[+name]], {name} and :name.

javascript
_('my_component_title')                      // "My component"
_('my_component_welcome', { name: 'John' })  // from "Hello, {name}!" → "Hello, John!"

Lexicons are read from window.MODx.lang. Load topics in the controller:

php
public function getLanguageTopics()
{
    return ['mycomponent:default'];
}

useModx

Access to window.MODx.

javascript
import { useModx } from '@vuetools/useModx'

const { config, siteId, isManager, getSetting } = useModx()
Property / methodTypeDescription
configComputedRef<object>MODx.config
userComputedRef<object>MODx.user
siteIdComputedRef<string>Auth token MODx.siteId
hasPermission(key)booleanWhether the user has permission key
getSetting(key, default?)*Value from MODx.config
getManagerUrl(path?)stringManager URL
getAssetsUrl(component)stringComponent assets URL
getConnectorUrl(component)stringComponent connector URL
getContextKey()stringCurrent context key
isManager()booleanWhether the code runs in the manager
fireEvent(name, data?)voidFire an ExtJS MODx event

config, user and siteId are Vue computed refs: use config.assets_url in a template, config.value.assets_url in code.

usePermission

User permission checks. Permissions come from window.MODx.perm.

javascript
import { usePermission } from '@vuetools/usePermission'

const { can, canAny, canAll } = usePermission()
MethodReturnsDescription
can(key)booleanWhether the user has permission key
canAny(keys)booleanWhether the user has any of the permissions
canAll(keys)booleanWhether the user has all permissions
getAll()objectAll user permissions
javascript
const { can } = usePermission()
const canEdit = computed(() => can('my_component_edit'))

Shortcuts for common MODX permissions exist too: canCreateResource(), canEditResource(), canViewUsers(), canClearCache() and others — all called without arguments.

useApi

HTTP client for the standard MODX connector API (?action=processor/path).

javascript
import { useApi } from '@vuetools/useApi'

const { get, post, put, delete: del } = useApi()
MethodDescription
get(action, params?)GET request
post(action, params?, options?)POST request
put(action, params?, options?)PUT request
delete(action, params?)DELETE request
buildUrl(action, params?)Build a URL without sending
javascript
const users = await get('security/user/getlist', { limit: 20 })
await post('security/user/create', { username: 'newuser' })

POST and PUT send FormData by default. For a JSON body pass { json: true } as the third argument. The HTTP_MODAUTH token (from MODx.siteId) is added automatically. On a success: false response the method throws an error carrying a data field.

Custom router

useApi targets the standard MODX connector. If your component has its own router, add a local request.js — see Custom API client.

usePrimeVueLocale

PrimeVue locales: DataTable filter labels, DatePicker/Calendar buttons and headers.

javascript
import { getPrimeVueLocale } from '@vuetools/usePrimeVueLocale'
import { PrimeVue } from 'primevue'
import { getActiveTheme } from '@vuetools/useTheme'

app.use(PrimeVue, { ...getActiveTheme(), locale: getPrimeVueLocale() })
FunctionReturnsDescription
getPrimeVueLocale(cultureKey?)objectLocale by code; without an argument — by MODx.cultureKey

Codes: de, en, es, fr, pl, ru, uk. An unknown code yields the English locale. The locale is not reactive: to change language without a page reload, pass a new cultureKey or recreate the app.

useTheme

The active theme. Full page: Theme.

javascript
import { getActiveTheme } from '@vuetools/useTheme'
import { PrimeVue } from 'primevue'

app.use(PrimeVue, getActiveTheme())
FunctionReturnsDescription
getActiveTheme(name?){ theme }Theme config for app.use(PrimeVue, …)
getThemeName(name?)stringActive theme name (aura or modx)

Without an argument the theme comes from the vuetools.theme setting (delivered via window.VueTools); an unknown value falls back to aura.