Container for puppet manicure and packaging

Is there a way that I can say that the base / puppet will not automatically add the container tag when rendering the view to the area?

For example, let's say I want to display a list of items. The way I want to do this is that one composite view looks like this:

<ul> </ul> 

And then the representation of the element is as follows:

 <li><%= title %></li> 

Now I can easily get the same result by changing the fact that the tag used for the automatically generated item is the biggest reason that I will not have the tag automatically generated by the trunk / puppet, because I want to save as much as possible html in as soon as possible. If for some reason I want to change the list to a table, if all the HTML is contained in the templates, I need to change only two template files. Another way would require me to change 2 template files and 2 javascript files (the smaller the file I have to change to make the changes, the less chance of error). I just like to have that level of separation.

+4
source share
1 answer

Neither the base nor the puppet supported this. But I assume that if you can get this behavior with multiple settings.

Backbone.View has a _ensureElement method that builds el from tagName and className if el not provided.

You can override _ensureElement to display the template first and then use its first tag name as tagName for presentation. You also need to override Marionette.Renderer.render to remove the external template tag.

There may be a better choice of methods to override this logic. I would also advise you to specify a flag somewhere to rotate this behavior selectively so that you can mix and match as needed, which would also help in debugging.

0
source

Source: https://habr.com/ru/post/1433437/


All Articles