Website Viewtool

Last Updated: Jun 11, 2024
documentation for the dotCMS Content Management System

The Website viewtool is a helper tool that helps to retrieve path elements — hosts, folders, or subfolders — for a site.

The following example shows how the WebsiteWebAPI is mapped in the toolbox.xml file:

    <tool>
        <key>website</key>
        <scope>request</scope>
        <class>com.dotcms.rendering.velocity.viewtools.WebsiteWebAPI</class>
    </tool>

Velocity Methods

MethodReturn Type
$website.getFolder()Folder object
$website.getSubFolders()List of Folder objects
$website.getHost()Host object
$website.getHostName()String

Get Folder

Takes a folder path and host to retrieve the folder as an object.

ArgumentTypeDetails
Folder PathStringPath of folder to retrieve as object.
Host IDStringIdentifier of the Site/Host containing the folder.

Examples:

## $website.getFolder(String folderPath, String hostId)
$website.getFolder("/application/apivtl/search", "48190c8c-42c4-46af-8d1a-0cd5db894797")

Get Subfolders

Takes either a Folder object or a folder path and host id to retrieve an array of Folder objects.

ArgumentTypeDetails
Parent FolderString or Folder objectPath or object of folder containing the child Folder objects to fetch.
Host IDStringOptional if Folder object is supplied as first argument. Identifier of the Site/Host containing the folder.

Examples:

## $website.getSubFolders(String parentFolder, String hostId)
#set($subfolders1 = $website.getSubFolders("/application/apivtl", "48190c8c-42c4-46af-8d1a-0cd5db894797"))
#foreach($f in $subfolders1)
    $f
#end

## $website.getSubFolders(Folder parentFolder)
#set($folder1 = $website.getFolder("/application/apivtl/search", "48190c8c-42c4-46af-8d1a-0cd5db894797"))
#set($subfolders2 = $website.getSubFolders($folder1))
#foreach($f in $subfolders2)
    $f
#end

Get Host

Returns the Host/Site as an object.

ArgumentTypeDetails
Host IDStringIdentifier of the Site/Host.

Examples:

## $website.getHost(String hostId)
#set($hostbody = $website.getHost("8a7d5e23-da1e-420a-b4f0-471e7da8ea2d"))
$hostbody
$hostbody.identifier

Get Hostname

Returns the Host/Site name as a string.

ArgumentTypeDetails
Host IDStringIdentifier of the Site/Host containing the folder.

Examples:

## $website.getHostName(String hostId)
$website.getHostName("8a7d5e23-da1e-420a-b4f0-471e7da8ea2d")

Javascript Methods

The JavaScript implementation of this viewtool is much simpler, containing only one method at the time of writing. Additionally, this tool is accessed in custom JavaScript endpoints through the variable site instead of $website.

MethodReturn Type
site.getCurrentSiteId()String

Get Current Site ID

Returns the Host/Site ID as a string.

ArgumentTypeDetails
RequestRequest ObjectAccepts request from context.

Example:

const request = context.request;
const siteID = site.getCurrentSiteId(request);

On this page

×

We Dig Feedback

Selected excerpt:

×