Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Functions are injected through ctx variable into template execution scope and are used to provide convenience methods for some of the encapsulated raw low level functions of the platform (e.g. access to HTTP request context, template inclusion mechanism, pre-processing parameters etc). 

 

Version
Function
Param
Example
Description
1.x.xviewUri 

 

Code Block
ctx.builder.a('href', ctx.viewUri, 'link')

 

Retrieves current URL
1.x.xbuilder 
Code Block
ctx.builder.html {
  body {
    div('Some text');
  }
}
Markup builder
1.x.xincluderelativePath
Code Block
ctx.builder.section('class': 'blog') {
    div('class': 'container') {
        div('class': 'row') {
            ctx.include('component/' + (centralView ?: 'EmptyCentralView') + '.groovy');
        }
    }
}
Include a script file in current template execution scope
1.x.xincludeurlrelativePath
Code Block
ctx.includeurl '/internal/breadcrumbs';

ctx.builder.section('class': 'blog') {
    div('class': 'container') {
        div('class': 'row') {
            ctx.includeurl "/internal/categorybody?categoryId=${sf.categoryId}";
        }
    }
}
Invoke a sub request result of which will be amalgamated in final response
3.5.xincludevariant

relativePath,

defaultPath

Code Block
ctx.includevariant(_optTemplate + '.groovy', 'SkuOptionsDim.groovy');
Include a script variation (if one exists) or default otherwise in current template execution scope
1.x.xpagecache

timeout,

keyType

Code Block
ctx.pagecache('1d', '-');

Meta data to instruct page template caching.

timeout:

  • d (days),
  • h (hours),
  • m (minutes),
  • s (seconds)

keyType:

  • '-' - all users
  • 'user' - user specific cache
1.x.xinlineResourcerelativePath
Code Block
div('class': 'col-xs-12 col-md-4') {

    mkp.yieldUnescaped( ctx.inlineResource('StandardFooterNavIncludeSocial.html') );

}


Inline file in the generated markup
1.x.xcontent
contentId
Code Block
div('class': 'form-group') {

    mkp.yieldUnescaped(ctx.content('reset_resetform_content_include'));

}


Retrieve content from CMS as a string by SEO URI
1.x.xcontentExistscontentId
Code Block
if (ctx.contentExists(_optCms)) { // shop specific rendering

    mkp.yieldUnescaped(ctx.dynamicContent(_optCms, [
            'product': product,
            'skus': _skus,
            'sku': _sku,
            'fc': _fc,
            'optionsModel': _optionsModel,
            'optionsModelItem': _option
    ]));

}
Check if content is defined in CMS
1.x.xdynamicContent

contentId,

parameters

Code Block
if (ctx.contentExists(_optCms)) { // shop specific rendering

    mkp.yieldUnescaped(ctx.dynamicContent(_optCms, [
            'product': product,
            'skus': _skus,
            'sku': _sku,
            'fc': _fc,
            'optionsModel': _optionsModel,
            'optionsModelItem': _option
    ]));

}
Retrieve content from CMS as a string by SEO URI. Content is preprocessed by template engine.
1.x.xmsgmessageKey
Code Block
span(ctx.msg('addToCompare'));
Retrieves message from shop.properties.xml
1.x.xmsgf

messageKey,

parameters

Code Block
a('href': ctx.URL('logout'), 'rel': 'nofollow', 'title': ctx.msgf('logoffTitle', ['customer': sf?.managerName])) {
    span ctx.msg('logoffLabel');
}
Retrieves message from shop.properties.xml. Message is preprocessed by template engine.
1.x.xcontentURLcontentId
Code Block
a('href': ctx.contentURL('license'), 'rel': 'bookmark') {
    span(ctx.msg('licenceInfo'));
}
Generate content page relative URL
1.x.xcategoryURLcategoryId
Code Block
a('rel': 'bookmark', 'href': ctx.categoryURL('notebooks')) {
    img('src': ctx.resourceURL('image/baner1.png'));
}
Generate category page relative URL
1.x.xproductURL

productId,

fc

Code Block
 def _url = ctx.productURL(_item.product.uri, _item.supplierCode);
Generate product page relative URL for specific fulfilment centre
1.x.xskuURL

productId,

fc

Code Block
 a('rel': 'bookmark', 'href': ctx.skuURL(_item.productSku.uri, _item.supplierCode)) {
    span(ctx.macroProductName.name(_item.productSku));
}
Generate SKU page relative URL for specific fulfilment centre
1.x.xresourceURLpath
Code Block
 a('rel': 'bookmark', 'href': ctx.categoryURL('notebooks')) {
    img('src': ctx.resourceURL('image/baner1.png'));
}
Generate resource relative URL
1.x.xfilteredURLpath
Code Block
def _selected = _multi && ctx.macroFormUtils.values(_filteredNavBlock.code).contains(_filteredNavBlockValue.value);

def _path = _filteredNavBlock.code + '/' + ctx.encodeURI(_filteredNavBlockValue.value);
def _href;
if (_selected) {
    _href = ctx.filteredURL('').replace(_path, '').replace('//', '/');
} else {
    _href = ctx.filteredURL(_path);
}
Generate relative URL including filter navigation parameters
1.x.xURLpath
Code Block
a('href': ctx.URL('management/customers'), 'rel': 'nofollow') {
    span ctx.msg('managedCustomers');
}
Generate relative URL
4.1.xtoAbsoluteURL

url,

scheme

Code Block
 a('href': ctx.toAbsoluteURL(ctx.URL('management/customers'), 'https'), 'rel': 'nofollow') {
    span ctx.msg('managedCustomers');
}
Convert relative URL to absolute one
1.x.xencodeURIuri
Code Block
 input('type': 'hidden', 'name': 'returnTo', 'value': ctx.encodeURI('checkout?step=address'));
Encode value
1.x.xdecodeURIuri
Code Block
a('href': ctx.URL(ctx.decodeURI(ctx.macroFormUtils.value('returnTo', 'profile'))), 'class': 'btn btn-default', 'title': ctx.msg('cancel')) {
    mkp.yieldUnescaped(ctx.msg('cancel'));
}
Decode value

Variables

Variables are injected through sf variable into template execution scope and provide runtime context for current request (e.g. access to current shop, cart, filter navigation scope etc) 

...