Resources: Can't pass in string var with .resources.Concat

Trying to rename a js file based on a site variable (.Site.Params.projectname). I don’t have any issues with other javascript resources, but for a multitude of reasons, I need to also be running Webpack to create an app.min.js (written to assets/scripts/dist/app.min.js) that I want to rename without having to change things in the webpack.config.js.

Here is what I have so far:

<!--Inside a scripts.html partial. Everything else runs fine in this partial (tested), except this block:-->
{{ $jsPre := path.Join "/js/" $.Site.Params.projectname  }}
{{ $targetJsPath := string (path.Join $jsPre ".min.js") }}
{{ $projDevScript1 := resources.Get "scripts/dist/app.min.js" }}
{{ $projDevScript2 := resources.Get "scripts/dist/additional.js" }}
{{ $projectscript := slice $projDevScript1 $projDevScript2| resources.Concat $targetJsPath | minify | fingerprint }}
<script src="{{ $projectscript.RelPermalink }}">

So if I have projectname set to acme, I know that $targetPath is correctly set to /js/acme.min.js. However, things stop working at $projectscript. I am getting the following error in the terminal (using OSX):

ERROR 2018/07/21 12:34:01 Error while rendering "page" in "page-templates/": template: page-templates/single.html:14:3: executing "page-templates/single.html" at <partial "scripts.htm...>: error calling partial: html/template:partials/scripts.html:16:12: {{if}} branches end in different contexts: {stateText delimNone urlPartNone jsCtxRegexp attrNone elementNone <nil>}, {stateJS delimNone urlPartNone jsCtxRegexp attrNone elementScript <nil>}
ERROR 2018/07/21 12:34:01 Error while rendering "section" in "developers/": template: _default/section.html:15:5: executing "_default/section.html" at <partial "scripts.htm...>: error calling partial: html/template:partials/scripts.html:16:12: {{if}} branches end in different contexts: {stateText delimNone urlPartNone jsCtxRegexp attrNone elementNone <nil>}, {stateJS delimNone urlPartNone jsCtxRegexp attrNone elementScript <nil>}
ERROR 2018/07/21 12:34:01 Error while rendering "page" in "developers/": template: _default/single.html:15:5: executing "_default/single.html" at <partial "scripts.htm...>: error calling partial: html/template:partials/scripts.html:16:12: {{if}} branches end in different contexts: {stateText delimNone urlPartNone jsCtxRegexp attrNone elementNone <nil>}, {stateJS delimNone urlPartNone jsCtxRegexp attrNone elementScript <nil>}
ERROR 2018/07/21 12:34:01 Error while rendering "section" in "page-templates/": template: _default/section.html:15:5: executing "_default/section.html" at <partial "scripts.htm...>: error calling partial: html/template:partials/scripts.html:16:12: {{if}} branches end in different contexts: {stateText delimNone urlPartNone jsCtxRegexp attrNone elementNone <nil>}, {stateJS delimNone urlPartNone jsCtxRegexp attrNone elementScript <nil>}
ERROR 2018/07/21 12:34:01 Error while rendering "home" in "": template: index.html:15:5: executing "index.html" at <partial "scripts.htm...>: error calling partial: html/template:partials/scripts.html:16:12: {{if}} branches end in different contexts: {stateText delimNone urlPartNone jsCtxRegexp attrNone elementNone <nil>}, {stateJS delimNone urlPartNone jsCtxRegexp attrNone elementScript <nil>}
Total in 49 ms
ERROR 2018/07/21 12:34:01 Failed to rebuild site: logged 5 error(s)

The error message suggests you’re not showing us the complete template. That makes it impossible to help.

Thanks for the reply @bep. This is the only part of this partial that seems to be the issue. That is, when I remove it, there are no issues. Here is the entire partial for scripts.html, which I include via the obvious {{ partial "scripts.html" . }} in baseof.html.

<!-- Scripts from config.toml-->
{{- if and (.Site.Params.includejq2) (not .Site.Params.includebsjs ) -}}
<script src="{{ "js/jquery-2.2.4.min.js" | relURL}}"></script>
{{- else if and (.Site.Params.includejq3) (not .Site.Params.includebsjs) -}}
<script src="{{ "js/jquery-3.3.1.min.js" | relURL}}"></script>
{{- else if .Site.Params.includebsjs -}}
<script src="{{ "js/jquery-3.3.1.slim.min.js" | relURL}}"></script>
<script src="{{ "js/popper-1.14.3.min.js" | relURL}}"></script>
<script src="{{ "js/bootstrap-4.1.2.min.js" | relURL}}"></script>
{{- end -}}

<!--Do not include DS scripts in individual page templates-->
{{- if or (ne .Section "page-templates") .IsNode -}}
	{{ $dslunr := resources.Get "/design-system-scripts/lunr.js" }}
	{{ $dshighlight := resources.Get "/design-system-scripts/highlight.pack.js" }}
	{{ $dsclipboard := resources.Get "/design-system-scripts/clipboard.min.js" }}
	{{ $dssearch := resources.Get "/design-system-scripts/design-system-search.js" }}
  {{ $dsaddscripting := resources.Get "/design-system-scripts/design-system-additional-scripting.js" }}
  {{ $dstabs := resources.Get "/design-system-scripts/design-system-component-tabs.js" }}
	{{ $dsscripts := slice $dslunr $dshighlight $dsclipboard $dssearch $dsaddscripting $dstabs | resources.Concat "/js/design-system-script.min.js" | minify | fingerprint}}
	<script src="{{ $dsscripts.RelPermalink }}"></script>
{{- end -}}


<!-- ADD PAGE TEMPLATE INFO SCRIPT FOR PAGE TEMPLATES -->
{{- if eq (.Section | urlize) "page-templates" -}}
<!-- Adds page templates modal that shows content written for each of the page templates. See wiki for more information-->
	{{ $dspt := resources.Get "/design-system-scripts/design-system-toggle-page-template-info.js" | minify | fingerprint }}
	<script src="{{ $dspt.RelPermalink }}"></script>
{{- end -}}

<!-- The script created by webpack during local development, renamed according to projectname variable in config.toml -->
{{ $jsPre := path.Join "/js/" $.Site.Params.projectname  }}
{{ $targetJsPath := string (path.Join $jsPre ".min.js") }}
{{ $projDevScript1 := resources.Get "scripts/dist/app.min.js" }}
{{ $projDevScript2 := resources.Get "scripts/dist/additional.js" }}
{{ $projectscript := slice $projDevScript1 $projDevScript2| resources.Concat $targetJsPath | minify | fingerprint }}
<script src="{{ $projectscript.RelPermalink }}"> 




<!-- GOOGLE ANALYTICS -->

{{ with .Site.Params.googleanalyticsid }}
<script async>
(function() {
  var localTest = new RegExp(/localhost/i);
  var hostName = window.location.hostname;
  if (localTest.test(hostName)) {
  	console.log("Development, so no Google Analytics!");
    return;
  } else {
    (function(i, s, o, g, r, a, m) {
      i['GoogleAnalyticsObject'] = r;
      i[r] = i[r] || function() {
        (i[r].q = i[r].q || []).push(arguments)
      }, i[r].l = 1 * new Date();
      a = s.createElement(o),
        m = s.getElementsByTagName(o)[0];
      a.async = 1;
      a.src = g;
      m.parentNode.insertBefore(a, m)
    })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

    ga('create', '{{.}}', 'auto');
    ga('send', 'pageview');
  }
})();
</script>
{{ end }}

The error says that and if ends in a different context. e.g.

{{ if true }}
<script>

{{ end }}
</script>

Which has nothing to do with your title of this issue. But it should give you something to look for.

Gah! You’re absolutely right. In my example above, it was my failure to include a closing </script> tag. Thanks so much for your help, @bep!