0

I am using Handlebars for a site I am building for rendering the sites content and language control. To make things easier I want to make a function where I can pass in the the "page" as an argument.

Here is the function I have started on:

config.renderLanguage = function(page) {
    var soruce = $('#body').html();
    var template = Handlebars.compile(soruce);
    // "this" is my language file.
    $('#body').append(template(this.language_file.page.body));
};

I assume that it won't work because when "page" comes in, it is a string, resulting in an error. So the question is really how I can convert the argument so it can be used in the dot notation.

1 Answer 1

1

You cannot.

If you want to use variables, then you must use square bracket notation.

Sign up to request clarification or add additional context in comments.

4 Comments

I am sorry to hear that :-) Do you have any idea on how I could go about this with a different approach?
Yes. Use square bracket notation.
Thats what you said before. Thanks :-)
That's because it is still the solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.