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

How to implement a handlebar plugin #181

Open
chriscodeweb opened this issue Apr 30, 2019 · 0 comments
Open

How to implement a handlebar plugin #181

chriscodeweb opened this issue Apr 30, 2019 · 0 comments

Comments

@chriscodeweb
Copy link

Hello, I have succesfully implemented the handlebars-loader in webpack. Great work btw! 👍
For the translations in handlebar I need this plugin https://www.npmjs.com/package/handlebars.element

My goal is to work with a custom element. because I also use a gettext-extractor that queries for a selector (ex. <translate>mytranslation</translate>) You can't query with the gettext-extractor handlebar code like this {{#translate}}Tree{{/translate}} in your template.

I created a helper and have this code so far. And when I have a element <foo>test</foo>
It should work, but it does not.

Does anyone have a idea to make this work?

Thanks in advanced!

`import Handlebars from "handlebars";
require("handlebars.element").default(Handlebars);

export default function helpersHandlebarsdcTranslate(options) {
Handlebars.registerElement("foo", function(attributes) {
var div = document.createElement("div");
div.innerText = "Hi There " + (attributes.title ? attributes.title : "guest");

	if (attributes.red) {
		div.className = "red";
	} else if (attributes.green) {
		div.className = "green";
	} else if (attributes.blue) {
		div.className = "blue";
	}

	return div;
}, {
	booleans: ["red", "green", "blue"]
});

}`

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