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

added loader that works from memory #617

Merged
merged 3 commits into from
Oct 28, 2022

Conversation

acole76
Copy link
Contributor

@acole76 acole76 commented Feb 17, 2022

This attempts to solve the issue with StringLoader where inheritance is not supported. This loader uses a flat hierarchy.

MemoryLoader memLoader = new MemoryLoader();
memLoader.addFile("home.html", "{% extends \"layout.html\" %}{% block title %} Home {% endblock %}\r\n"
			+ "\r\n"
			+ "{% block content %}\r\n"
			+ "	<h1> Home </h1>\r\n"
			+ "	<p> Welcome to my home page. My name is {{ name }}.</p>\r\n"
			+ "{% endblock %}");
memLoader.addFile("layout.html", "<!DOCTYPE html>\r\n"
		+ "<html>\r\n"
		+ "    <head>\r\n"
		+ "        <title>Hello Pebble</title>\r\n"
		+ "    </head>\r\n"
		+ "    <body>\r\n"
		+ "        {% block content %}{% endblock %}\r\n"
		+ "    </body>\r\n"
		+ "</html>");
PebbleEngine engine = new PebbleEngine.Builder().loader(memLoader).build();
PebbleTemplate compiledTemplate = engine.getTemplate("home.html");
Map<String, Object> context = new HashMap<String, Object>();
context.put("name", "Mitchell");

Writer writer = new StringWriter();
compiledTemplate.evaluate(writer, context);

String output = writer.toString();
System.out.println(output)
```;

@ebussieres ebussieres added this to the 3.2.0 milestone Oct 28, 2022
@ebussieres ebussieres merged commit 97a6f70 into PebbleTemplates:master Oct 28, 2022
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

Successfully merging this pull request may close these issues.

2 participants