Page tree
Skip to end of metadata
Go to start of metadata

 

 

Overview  SaaS 

This document outlines key point on working with SFG templates.

Functions

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 

 

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

 

Retrieves current URL
1.x.xbuilder 
ctx.builder.html {
  body {
    div('Some text');
  }
}
Markup builder
1.x.xincluderelativePath
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
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

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

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
div('class': 'col-xs-12 col-md-4') {

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

}


Inline file in the generated markup
1.x.xcontent
contentId
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
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

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
span(ctx.msg('addToCompare'));
Retrieves message from shop.properties.xml
1.x.xmsgf

messageKey,

parameters

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
a('href': ctx.contentURL('license'), 'rel': 'bookmark') {
    span(ctx.msg('licenceInfo'));
}
Generate content page relative URL
1.x.xcategoryURLcategoryId
a('rel': 'bookmark', 'href': ctx.categoryURL('notebooks')) {
    img('src': ctx.resourceURL('image/baner1.png'));
}
Generate category page relative URL
1.x.xproductURL

productId,

fc

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

productId,

fc

 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
 a('rel': 'bookmark', 'href': ctx.categoryURL('notebooks')) {
    img('src': ctx.resourceURL('image/baner1.png'));
}
Generate resource relative URL
1.x.xfilteredURLpath
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
a('href': ctx.URL('management/customers'), 'rel': 'nofollow') {
    span ctx.msg('managedCustomers');
}
Generate relative URL
4.1.xtoAbsoluteURL

url,

scheme

 a('href': ctx.toAbsoluteURL(ctx.URL('management/customers'), 'https'), 'rel': 'nofollow') {
    span ctx.msg('managedCustomers');
}
Convert relative URL to absolute one
1.x.xencodeURIuri
 input('type': 'hidden', 'name': 'returnTo', 'value': ctx.encodeURI('checkout?step=address'));
Encode value
1.x.xdecodeURIuri
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) 

Example usage
def _total = sf.cartTotal;
VersionVariableDescription
1.x.xdeploymentModeDeployment mode as defined by "webapp.configuration" runtime constant
4.1.xserverNameRequest server name
1.x.xcontextPathRequest context path
4.1.xssoContextSSO context, injected by cart filter through SSO bridge
1.x.xrawRequestURIRaw request URI
1.x.xrawRequestURLRaw request URL
1.x.xrawIncludeURIRaw internal request URI
1.x.xrawRequestCookiesRaw request cookies
1.x.xrawRequestParametersRaw request parameters
1.x.xnavRequestParametersNavigation request parameters
1.x.xskuIdAndUriSku ID and URI pair
1.x.xproductIdAndUriProduct ID and URI pair
1.x.xcategoryIdAndUriCategory ID and URI pair
1.x.xcontentIdAndUriContent ID and URI pair
1.x.xsupplierFulfilment centre code
1.x.xfcFulfilment centre code (synonym for supplier variable)
1.x.xshopIdCurrent sales channel ID
1.x.xshopCodeCurrent sales channel code
1.x.xcustomerShopIdCurrent customer sales channel ID
1.x.xcustomerShopCodeCurrent customer sales channel code
1.x.xcategoryIdCategory ID
1.x.x (deprecated)shopLogoURLShop IMAGE0
1.x.xlocaleLocale ISO-2 code
1.x.xlocaleNameLocale full name
1.x.xlocaleObjectLocale java object
1.x.xsupportedLocalesSupported locales ISO-2 code list
1.x.xcurrencyCurrency three ISO-3 code
1.x.xcurrencyNameCurrency name
1.x.xsupportedCurrenciesSupported currencies ISO-3 code list
1.x.xcurrenciesConfigSupported currencies ISO-3 code and name pairs list
1.x.xloggedInFlag to indicate customer is logged in
1.x.xrequireCustomerLoginFlag to indicate if customer login is required
1.x.xcustomerNameLogged in customer name
1.x.xcustomerTypeLogged in customer type
1.x.xcustomerTagsLogged in customer tags
1.x.xmanagerNameLogged in manager name
1.x.xguestCheckoutEnabledFlag to indicate guest checkout is enabled (shop specific config "SHOP_CHECKOUT_ENABLE_GUEST")
1.x.xcheckoutAvailableFlag to indicate that checkout is available for current customer 
1.x.xrfqAvailableFlag to indicate that request for quote is available for current customer
1.x.xorderRequireApproveFlag to indicate order requires approval
1.x.xmetaPage meta data (available in /internal/pageheadmetaseodata include only)
1.x.xcartShopping cart object
1.x.xcartTotalCart total
1.x.xuseManufacturerSkuFlag to indicate to use manufacturer SKU instead of product SKU to render  (shop specific config "PRODUCT_DISPLAY_MANUFACTURER_CODE_SHOP")
1.x.xuseQuantityPickerFlag to indicate to use quantity picker (shop specific config "CART_ADD_ENABLE_QTY_PICKER")
1.x.xuseProductOverrideAttribute to use for product name override (shop specific config "SHOP_PRODUCT_NAME_OVERRIDE")
1.x.xaddressbookEditableFlag indicating that address book is editable by customer
1.x.xaddressbookBillingEditableFlag indicating that address book is editable by customer
1.x.xearliestNewProdInstantTime indicating earliest time to be considered as "new product"
1.x.xsearchGlobalOnlyFlag to indicate that "search global only" mode is enabled
1.x.xsearchDisableCompoundFlag to indicate that "compound search" mode should be disabled
1.x.xsearchDisableSuggestFlag to indicate that search suggest feature is disabled
1.x.xsearchSuggestMinCharsSearch suggest minimum characters trigger
1.x.xsearchSuggestMaxItemsSearch suggest maximum number of results to display
1.x.xsearchSuggestFadeOutSearch suggest "fade out" timeout
1.x.xshopNewsletterEnableEnable newsletter feature
1.x.xcategoryDisablePaginationDisable pagination on category pages
1.x.xcategoryDisableSortingDisable sorting on category pages
1.x.xcategoryDisablePageSizeDisable page size selector on category pages
1.x.xcategoryDisableShowMoreDisable "show more" button on category pages

 

 

 

 

  • No labels