google / closure-templates

A client- and server-side templating system that helps you dynamically build reusable HTML and UI elements

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

relative paths

shawnthompson opened this issue · comments

At work I inherited a JavaScript templating project which is built using Google Closure Templates and I am trying to convert it into a CI/CD project, make it open and let others use it and contribute to it.

Background

The project was created so that web applications and sites that use our template just have to point to a server setup as a CDN that hosted our files.

Issue

All our paths were set with an .environment template with if conditions for different servers our files reside on.

/**
 * @param cdnEnv Used to switch between qat, dev, and prod implementations.
 */
{template .environment}
/**{@param cdnEnv}*/
{if $cdnEnv=='qat'}
   https://qat.domain.com
{elseif $cdnEnv=='dev'}
   https://dev.domain.com
{else}
   https://domain.com{/if}/ourfiles/
{/if}
{/template}

Then we call it in the different templates to access our resource files (css, js, images, etc...)

<link rel="stylesheet" href='{call .environment data="all" /}css/theme.css'>

I want our templates to work no matter where we host the files, but if I change the paths to relative to the JS, once it gets injected in the page, it becomes relative to the page itself and breaks.

Is there a way to achieve this?

Thank you for your time,
Shawn