question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

After updating to Scriban 3.2.2, templates are no longer working

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
xoofxcommented, Dec 29, 2020

That would be great! Do you have enough here to work with, or would a sample application help?

I think I have enough, I will add a test to cover the regression you have discovered.

1reaction
xoofxcommented, Dec 30, 2020

Great, thanks for reporting this! 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

scriban/scriban: A fast, powerful, safe and lightweight ...
Scriban is a fast, powerful, safe and lightweight scripting language and engine for .NET, which was primarily developed for text templating with a...
Read more >
scriban/changelog.md at master
Fix issue when using a local variable inside an object initializer. Fix Template.Evaluate if used with Liquid. Fix argument out of the range...
Read more >
Error when adding scriban template to rendering variant ...
Yes, I added a scriban template with just the word "test" in there. As long as a scriban template is added to the...
Read more >
Text Templating Scriban | Documentation Center | ABP.IO
Defining Templates. Before rendering a template, you should define it. Create a class inheriting from the TemplateDefinitionProvider base class:.
Read more >
Remarkable update stripped my custom template
Just updated to a 3.2.2.1581 and it stripped out my custom template from all my calcs I had been doing. Anyway to get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found