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

include from array #45

Open
hakimihamdan88 opened this issue Jun 3, 2017 · 1 comment
Open

include from array #45

hakimihamdan88 opened this issue Jun 3, 2017 · 1 comment

Comments

@hakimihamdan88
Copy link

hakimihamdan88 commented Jun 3, 2017

possible to render include tag from array? I don't want to load from a file

@sanmai
Copy link
Contributor

sanmai commented Sep 25, 2017

There's a virtual filesystem in liquid/liquid in packagist. This is the package you will install with composer.

Used like this:

class MyFileSystem extends Liquid\FileSystem\Virtual
{
	public static function fromArray($array)
	{
		return new static(function ($path) use ($array) {
			if (isset($array[$path])) {
				return $array[$path];
			}

			return '';
		});
	}
}

And then:

$template = new Template();
$template->setFileSystem(MyFileSystem::fromArray(array(
		'example' => "Hello, {{ name }}!",
)));

$template->parse("{% include 'example' %}");
echo $template->render(array("name" => "World"));

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

2 participants