Wix Blocks: Creating a Namespace for Your App
A namespace is a unique indicator of your app, in the format of:
@prefix/suffix
The prefix is either your account name or your company name. The suffix usually indicates your app name.
- Import the app’s Velo backend and public functions in the Wix Editors.
- Reference your app’s collections both in the Velo code of Wix sites and in the app code in Blocks.
- Create widget-only apps with no backend or public code, or collections).
Namespace prefix
Account name
Your account name is your Wix user name. If you are a Wix Partner, it's your Wix Partner account name. For this option, your namespace format is:
@your-account-name/your-app-name
Company name
Your company name is defined in your Company Info in the Wix Developers Center. Use this option if you plan to publish your app in the Wix App Market. For this option, your namespace format is:
@your-company-name/your-app-name
- A company name that you put in your namespace must be unique in Wix. If someone used your company name and you think it might involve trademark infringement, please let us know.
- Your namespace can only include latin letters and numbers. If your company name includes non-latin letters, you'll need to change it in the Wix Developers Center to use it as the prefix of a namespace.
- If you change your company name in the Wix Developers Center, it will change the namespace of all future applications in your account.
Namespace suffix
- Use only lower-case letters, and numbers.
- No special characters or spaces.
- Must be unique within your account.
Using your namespace for collections
1import wixData from 'wix-data';
2
3// ...
4
5let toInsert = {
6 "title": "Mr.",
7 "first_name": "John",
8 "last_name": "Doe"
9};
10
11wixData.insert("@yourAccountName/yourApp/yourCollection", toInsert)
12 .then( (results) => {
13 let item = results; //see item below
14 } )
15 .catch( (err) => {
16 let errorMsg = err;
17 } );
18
Using your namespace to import functions
To import a public function from your app's code files, use this syntax:
import {yourFunctionName} from '@yourAccountName/yourAppName'
For example:
1import {getStock} from '@nathanb257/stockquotesfromapi';
2
3$w.onReady(function (){
4 getStock()
5});
To import from backend files, use this syntax:
import {yourFunctionName} from '@yourAccountName/yourAppName-backend'
For example:
1import { getStock } from '@nathanb257/add1-backend';