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

StringTemplate4 cloned templates (shadow) work only once, subsequent calls render empty values #72

Open
lafar6502 opened this issue May 23, 2017 · 1 comment

Comments

@lafar6502
Copy link

Here is a failing test
First template (t0) created with 'CreateShadow' works OK
Second (t1) does not, renders all model values as empty
ST4.0.8

`
public class Test
{
public string Name { get; set; }
public Test Parent { get; set; }
public string Title;
public decimal Age { get; set; }
public DateTime CreatedDate;

        public Test()
        {
            Name = "name of test";
            Title = "titel titel";
            Age = 198.88m;
            CreatedDate = DateTime.Now;
        }
    }

    [TestMethod]
    public void ReuseTemplateTest()
    {
        //temp\sttest is empty dir, just for test
        var stg = new TemplateRawGroupDirectory("c:\\temp\\sttest", '$', '$');

        var tpl = new Template(stg, "$model.Name$ $model.Title$");
        var mdl = new Test { Name = "zzzyzx", Title = "mmm" };
        var t0 = tpl.CreateShadow();
        t0.Add("model", mdl);
        var txt0 = t0.Render();
        Assert.IsTrue(txt0.Contains(mdl.Title) && txt0.Contains(mdl.Name));

        var t1 = tpl.CreateShadow();
        t1.Add("model", mdl);
        var txt1 = t1.Render();
        Assert.IsTrue(txt1.Contains(mdl.Title) && txt1.Contains(mdl.Name));
    }

`

@lafar6502
Copy link
Author

lafar6502 commented May 23, 2017

Update - possible workaround is to use
TemplateGroup.CreateStringTemplateInternally(tpl.impl)
for cloning the template
have no idea if this is the correct approach

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

1 participant