Support existing values in the markup as defaults
garthbongers opened this issue · 1 comments
One lacking feature in HTL that I enjoyed from the Zope Template Attribute Language (TAL) is the ability to fallback to default values already set in the markup.
This would enable the existing markup (whether they're element names or attribute values or other content) to be preserved should an HTL expression evaluate to a decision of inaction. The TAL approach is to use the default
keyword.
For example:
<h1 data-sly-element="${ someCondition ? 'h2' : default}">Text</h1>
- would see the tag name being left alone should the condition fail<span class="abc" data-sly-attribute.class="${someClass || default}"></span>
- would see theclass
attribute being preserved shouldsomeClass
evaluate to false.<div id="myDiv" data-sly-text="${someNewContent || default}">Some <b>default</b> content</div>
- would see the existing markup in#myDiv
kept intact shouldsomeNewContent
evaluate to false.
Maybe all of this is already doable, and I've simply overlooked it?
Thank you!
There's no similar concept to the default
keyword. But you can still do all of these with the current spec, you just need to explicitly state the default value.
-
<h1 data-sly-element="${ someCondition ? 'h2' : 'h1'}">Text</h1>
replacesh1
withh2
only ifsomeCondition
is true. In the current (Sling) implementation you can also use${ someCondition ? 'h2' : ''}
but the spec says the element name is required. -
<span class="abc" data-sly-attribute.class="${someClass || 'abc'}"></span>
works, you could condense it to<span data-sly-attribute.class="${someClass || 'abc'}"></span>
-
<div id="myDiv" data-sly-text="${someNewContent || 'Some <b>default</b> content' @ context='html'}">Some <b>default</b> content</div>
works, you could also addi18n
to the expression. You can shorten this to<div id="myDiv" data-sly-text="${someNewContent || 'Some <b>default</b> content' @ context='html'}"></div>