code: public CmsTemplateContext getTemplateContext(
          String providerName,
          CmsObject cms,
          HttpServletRequest request,
          CmsResource resource) {
  
          I_CmsTemplateContextProvider provider = getTemplateContextProvider(providerName);
          if (provider == null) {
              return null;
          }
          String cookieName = provider.getOverrideCookieName();
          String forcedValue = null;
          if (request != null) {
              String paramTemplateContext = request.getParameter(CmsGwtConstants.PARAM_TEMPLATE_CONTEXT);
              if (!CmsStringUtil.isEmptyOrWhitespaceOnly(paramTemplateContext)) {
                  forcedValue = paramTemplateContext;
              } else if (cookieName != null) {
                  forcedValue = CmsRequestUtil.getCookieValue(request.getCookies(), cookieName);
              }
          }
          if (forcedValue != null) {
              Map<String, CmsTemplateContext> contextMap = provider.getAllContexts();
              if (contextMap.containsKey(forcedValue)) {
                  CmsTemplateContext contextBean = contextMap.get(forcedValue);
                  return new CmsTemplateContext(
                      contextBean.getKey(),
                      contextBean.getTemplatePath(),
                      contextBean.getMessageContainer(),
                      contextBean.getProvider(),
                      contextBean.getClientVariants().values(),
                      true);
  
              }
          }
          return provider.getTemplateContext(cms, request, resource);
      }
docs: Gets the template context to use.<p>
  
  @param providerName the name of the template context provider
  @param cms the current CMS context
  @param request the current request
  @param resource the current resource
  
  @return the current template context