1

I develop a jQuery plugin which produces HTML output, currently something like

<ul>
  <li><img></img></li>
  ...
</ul>

But actually, I would like to let the user of my plugin chose the HTML markup which gets generated, so for instance he passes a template string from which my plugin produces the output. But I don't know how.

Are there any best practices / "patterns" on how to achieve such a functionality?

2 Answers 2

1

The easiest way is to allow for an optional rendering function param and pass it the element(s). This way you have maximum control with minimal effort. Example:

$('#id').my_action(param1, function (e1, e2) {
    $('#target1').append(e1);
    $('#target2').append(e2);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, that is a great idea... Anyway I'll leave the question open for a bit, maybe there are some more ideas...
0

Take a look at the Fluid Renderer. I believe they're doing something very similar to what you describe.

Comments

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.