Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a variable in a link href #221

Open
robfig opened this issue Dec 1, 2020 · 3 comments
Open

Using a variable in a link href #221

robfig opened this issue Dec 1, 2020 · 3 comments

Comments

@robfig
Copy link

robfig commented Dec 1, 2020

This template:

{namespace main}

{template .main}
{@param appName: string}
    <link rel="stylesheet"
          type="text/css"
          href="/{$appName}/public/stylesheets/styles.css">
{/template}

Fails to compile with this error:

/Users/robfig/closure-templates/test.soy:7: error: Invalid or ambiguous syntax prevents Soy from escaping this template correctly:
- TrustedResourceUris containing dynamic content must have a fixed scheme (https) and host using one of the following formats:
  * https://foo/
  * //foo/
  * /foo
or move the calculation of this URL outside of the template and use an ordaining API.
7:           href="/{$appName}/public/stylesheets/styles.css">
                   ^

I don't understand why -- it is exactly the third format mentioned in the error message. What am I doing wrong?

EDIT: Here are other URLs that result in the same error:

  • /foo/{$appName}/public/stylesheets/styles.css
  • //{$domain}/foo
  • http://localhost:3000/app/{$appName}.css
robfig pushed a commit to robfig/closure-templates that referenced this issue Dec 1, 2020
@robfig
Copy link
Author

robfig commented Dec 1, 2020

To reproduce locally, checkout commit robfig@caaba74 and run bazel run :CompileSoy -- `pwd`/test.soy from the repo root.

@robfig
Copy link
Author

robfig commented Dec 3, 2020

Pinging @emspishak for any thoughts -- is this working as intended?

@lpellegr
Copy link

lpellegr commented Dec 27, 2020

@robfig I am quite new to Closure templates and experienced a similar issue. A solution that is working is to pass the URI to set as a param of type trusted_resource_uri and then using it as the href attribute value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants