Skip to content

After updating to Scriban 3.2.2, templates are no longer working #291

Closed
@gep13

Description

@gep13

This issue was raised as a result of a Twitter conversation.

We have a Scriban template, made up of the following files:

index.sbn

{{-
    include 'release-info'
    if milestone.target.description
        include 'milestone'
    end
    include 'issues' | string.rstrip
    if template_kind == "CREATE"
        include 'create/footer'
    end
~}}

release_info

{{
    if issues.count > 0
        if commits.count > 0
}}As part of this release we had [{{ commits.count }} {{ commits.count | string.pluralize "commit" "commits" }}]({{ commits.html_url }}) which resulted in [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?closed=1) being closed.
{{      else
}}As part of this release we had [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?closed=1) closed.
{{      end
    else if commits.count > 0
}}As part of this release we had [{{ commits.count }} {{ commits.count | string.pluralize "commit" "commits" }}]({{ commits.html_url }}).
{{  end -}}

milestone.sbn


{{ milestone.target.description }}

issues


{{ for issue_label in issue_labels
    include 'issue-details'
end }}

issue-details

__{{ issue_label }}__

{{ for issue in issues.items["issue_label"]
    include 'issue-note'
end }}

issue-note

- [__#{{ issue.number }}__]({{ issue.html_url }}) {{ issue.title }}

create/footer

{{ if config.create.include_footer }}

### {{ config.create.footer_heading }}

{{  if config.create.milestone_replace_text
        replace_milestone_title config.create.footer_content config.create.milestone_replace_text milestone.target.title
    else
        config.create.footer_content
    end
end }}

When using this, in combination with a model/context similar to the following (NOTE: issues, issuesDict, numberOfCommits, commitsLink, _targetMilestone, previousMilestone haven't been shown for brevity):

var templateModel = new
{
    Issues = new
    {
        issues.Count,
        Items = issuesDict,
    },
    Commits = new
    {
        Count = numberOfCommits,
        HtmlUrl = commitsLink,
    },
    Milestone = new
    {
        Target = _targetMilestone,
        Previous = previousMilestone,
    },
    IssueLabels = issuesDict.Keys.ToList(),
};

And then rendering the template using the following:

image

The complete code can be seen in this PR

It all works when using Scriban 2.1.4. However, when trying to run the same code in 3.2.2, we get the following error message in one of our unit tests:

image

 System.AggregateException : One or more errors occurred.
      ----> Scriban.Syntax.ScriptRuntimeException : resource://default/create/issue-details(3,30) : error : Cannot access target `issues.items` with a null indexer: issues.items[issue_label]

Do you have any suggestions about what needs to be changed in our current usage of Scriban to get this to work in 3.2.2?

Please let me know if you need any more details.

Adding @AdmiringWorm for visibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions