Self closing custom tag?
See original GitHub issueIs it possible to create self-closing custom tags? Is there some obvious thing I am missing, or would this require a change to the core?
For example, I want to be able to do this:
{% visor %}
In this situation I want my tag to output HTML, and will never accept content.
For reference, I’d prefer to do the above compared to the below, which I’m doing now:
{% visor %}{% endvisor %}
Issue Analytics
- State:
- Created 9 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Do custom elements require a close tag? - Stack Overflow
Yes. Custom elements require a closing tag. Only certain tags in HTML are allowed to be self-closing due to the parser.
Read more >Custom 'void' or self-closing elements (HTML parser ...
It's just another place for errors. A self closing tag means "the child content of this element is meaningless, and should even be...
Read more >[HTML5/JS] Define a custom self closing (void) HTML ...
Self closing HTML elements do not require or support a closing tag. Modern browsers support custom element tags and behavior using document.
Read more >How to deal with custom self closing tags after jQuery 3.5.0?
Closed Question heavily relies on custom self-closing HTML tags, e.g. <inlinechoice id="a" /> . These are processed server side as XML, but now ......
Read more >Custom Price Tags - Self Closing - No String Needed - Etsy
112 TAGS - Custom Price Tags - Self Closing - No String Needed - Personalized Custom Printed. QUANTITY: 112 SIZE: 1x1 square tops,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It would be difficult/impossible for nunjucks to determine what is a self closing tag and what is not, unless a difference syntax is used like:
Similar to html self closing tag but I really don’t see much use for this. You mention:
Wouldn’t it be easier to pass a function to your view and do:
If the function is required across all your views, make use of the new
addGlobal(name, func)
function.I do use template inheritance. My example is bare bones for simplicity.
I’m part of the dev team at a web studio, working on what I hope to be our next CMS system.
The example focuses on the page-meta module that I want to have the ability to inject & manage meta for all pages - be they CMS style pages that are created by the user or for controller style pages, pages from another module (i.e. a product management module), whatever. The sole responsibility of said module is to manage meta for pages. No other module will touch meta.
The great thing about nunjucks is that it has allowed me to code the meta module so it creates a
meta
block that can then be used in templates. The meta block will be given the relevant page (page is a local), and output nothing or the meta the end user (client) has entered to be the meta data for that page.This sort of thing allows us to “create once”, i.e. the meta module, then deploy it without modification, saving time. The client can edit the meta using said module’s admin features, we don’t ever have to think about meta tags again. For us, time is limited and this kind of thing helps immensely.
cmsblock
block that allows the dev to set default HTML, then wraps it in markup appropriate for Raptor to trigger for users with the correct permission.visor
block.permission
block that allows devs to wrap portions of template in a block that only outputs the contained HTML if the user accessing the page has the relevant permissions.I do understand template inheritance (it is awesome, I love nunjucks). I also understand your confusion as to why the hell anyone would want to do waht we’re doing. Believe me, for us it will be a massive time saver and allow us to focus on the fun parts of being at a web studio.
I realise we’re coming from completely different angles, that’s fine. Nunjucks is great and I can’t tell you how much I appreciate the effort you’ve all poured into creating it.
Self closing tags, async globals would be great for us, but nunjucks is no hardship without them!
Thanks!
P.S. apologies for the wall-o-text.