Skip to content

partially render templates for improved performance? #67

@dvtate

Description

@dvtate

I'd like to pre-populate some fields in a template that will always be the same in order to improve performance. For example:

Hello {{user}}, welcome to {{server}}.

I'd like to prepopulate {{server}} since it will not change and this template will be generated potentially millions of times.

My first naive attempt to do this looked like this:

kainjow::mustache::data global_data;
global_data.set("server", get_hostname());
kainjow::mustache::mustache t = kainjow::mustache::mustache(template_str).render(global_data);

However this deletes the {{user}} field so the code

t.render({ "user", provided_username });

results in

Hello , welcome to localhost.

So, two questions:

  1. Is there a way to do this without manually setting each variable to "{{variable}}"?
  2. Would could this actually improve performance?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions