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

Use html file directly as source in template #357

Open
pulkitmbd opened this issue Jul 6, 2021 · 2 comments
Open

Use html file directly as source in template #357

pulkitmbd opened this issue Jul 6, 2021 · 2 comments

Comments

@pulkitmbd
Copy link

pulkitmbd commented Jul 6, 2021

static void Main(string[] args)
{
    Console.WriteLine("Hello World!");

    var parser = new FluidParser();
    TemplateOptions options = new TemplateOptions();

    var fileProvider = new PhysicalFileProvider(Environment.CurrentDirectory);
    options.FileProvider = fileProvider;

    var model = new { Firstname = "Bill", Lastname = "Gates" };
    var source = File.ReadAllText("EmailTemplate.html");

    if (parser.TryParse(source, out var template, out var error))
    {
        var context = new TemplateContext(model, options);
        Console.WriteLine(template.Render(context));
        Console.WriteLine("Parsed successfully");
    }
    else
    {
        Console.WriteLine($"Error: {error}");
    }
}

In this code instead of converting file into string can we directly use the html file as template?

@deanebarker
Copy link
Contributor

I wrote this extension method that uses the same IFileProvider as include: https://gist.github.com/deanebarker/174bf177a7c393fdbaadfb44acf16273

parser.ParseFromFile("/path/to/file");

@sebastienros
Copy link
Owner

It's actually a feature that is provided by the "view" engine since it will also require extensibility for caching the files.
Hence the template engine itself doesn't provide that out of the box.

Not closing until it's ready, currently improving it.

@hishamco hishamco changed the title USe html file directly as as source in template Use html file directly as source in template Oct 12, 2021
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

3 participants