You are here: Best Practices > Identifying the Site Name

Identifying the Site Name

OVERVIEW

From within a script of HTML document, it may be necessary to dynamically identify the current site's identity. There are several ways to accomplish this task, which vary based on the context and location within a CPQ Cloud application.

Determining the identity of the current site is a critical step in creating portable, safe applications that can be copied across different testing, staging, and production instances. Whenever a resource is being referenced, externally or internally, make sure that a migration or site copy will not cause issues.

ClosedSome common areas where this occurs:

ADMINISTRATION

ClosedRelative vs Absolute Links

A relative link doesn't include the hostname, and refers to a resource based on it's starting position.

Examples of a relative path include the following:

There are some instances where using a relative path is enough. The path will automatically point to the appropriate resource, regardless of the environment.


ClosedFile Manager and Links

The challenge with linking to the File Manager is that the name of the site appears in two locations:

http://*SITENAME*.bigmachines.com/bmfsweb/*SITENAME*/image/

This can make it difficult to find link to the resource without having the site name available. Our strategy for finding the site name will vary based on where we are in CPQ Cloud.


ClosedIn Commerce BML

Use _system_supplier_company_name to identify the current site. This is a variable that stores the hostname of the current site, and is the same name that appears in the relative path to the File Manager.

sitename = lower(_system_supplier_company_name);

filemanager_path = "/bmfsweb/"+sitename+"/image/";

    The path to the File Manager is case sensitive. Account for this by using "lower()" in your function.

ClosedIn Configuration BML

You can use BMQL in combination with the commerce method to expose the site name in configuration. Assuming that the Quote Variable Name of the Commerce Document is quote_process, the script would look like this:

path = "";

records = BMQL("select filemanager_path from commerce.quote_process");

for item in records {

path = get(item, "filemanager_path");

}

return path;


ClosedDocument Engine XSL Snippets

There are some parameters available in the snippets that provide site-specific information:

<!-- Example XSL Snippet-->

<xsl:variable name="image_url">

<xsl:value-of select="concat($XSL_URL_PARAM, '/bmfsweb/',$XSL_COMPANYNAME_PARAM, '/image/my_folder/my_image.gif"/>

</xsl:variable>


ClosedDisplay XSL Templates

When modifying the Home Page XSL, Parts Search XSL, or other XSL display templates, the site name is available under the "page_data" element. Here's how to select it in the Home Page.

Notice that it is translated to lower case for the File Manager link.

<xsl:variable name="sitename" select="translate(/home_page/page_data/host_company, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>

<xsl:variable name="image_url" select="concat('/bmfsweb/',$sitename,'/image/my_folder/my_image.jpg')"/>


ClosedThe $BASE_PATH$ Parameter

$BASE_PATH$ is a variable supplied by CPQ Cloud that resolves to the full relative link of the File Manager. If you are adding a file to the header or footer, use the variable like this:

$BASE_PATH$ is available in the following areas:


ClosedHome Page Alt JS File

From within the Home Page Alt JS file, you have access to the global variable _BM_HOST_COMPANY, which refers to the current site name.

// outer function to avoid creating global variables

(function() {

var image_url = "/bmfsweb/"+_BM_HOST_COMPANY+"/image/my_folder/my_image.jpg";

}());


ClosedFrom Within the File Manager

Some files that you link to within the File Manager can have references within themselves. CSS files, for instance, may have links to images.

In the case of CSS, you can use relative links within your file to find other files in the File Manager. As long as the folder structure stays consistent, this will work across sites.

For example, assume the following directory structure in the File Manager:

From within style.css, you can link to photo.jpg as shown in the following example:


TROUBLESHOOTING

It can be difficult to recognize that a static reference has been broken, especially where it points to a similar resource on CPQ Cloud.

If there is a broken link, or a visible error, then this could be good news: it will point directly to the source of the problem.

Using global script search to search for the site name is another quick way to find hard-coded references.

Firebug has some features that can be helpful:

As an extreme measure, Ops can bring down a test site for a testing period. During this period a thorough screen should be run over the user side, looking for broken links and errors in functionality.

NOTES

RELATED TOPICS

Related Topics Link IconSee Also