n:ifcontent does not work with empty tags
- bernhard
- Member | 52
Please see this fiddle:
https://fiddle.nette.org/latte/#…
This behaviour is a problem for me! The background is that I'm using the ProcessWire CMS and that CMS has the capability to directly edit fields on the frontend:
https://i.imgur.com/A0rEt88.gif
This is great, but that means that the CMS injects some additional markup into the template.
So a simple <h1>My Headline</h1>
gets something like
<h1><span class='pw-edit-copy'>My Headline</span><span class='pw-edit-orig'>My Headline</span></h1>
That means that n:ifcontent does not work on these tags, which is annoying. I can use n:if instead and make sure that I return the raw value of the field there, but that's also a little annoying.
Could there be something like n:iftext ? I'd love to build such a feature on my own, but unfortunately I didn't understand the docs regarding how to create custom tags :(
Any pointers would be great! Thx in advance!
- Infanticide0
- Member | 112
<span> in <p> is content, I expect this behaviour.
n:iftext would be very useful, probably easy to implement (copy&paste
n:ifcontent tag class with some changes)
- bernhard
- Member | 52
Hey @Infanticide0 yeah I agree that markup is content – <svg> for example would also not be text, but markup and so the tag should appear. I just tried to explain my use case, but the headline is a little misleading I guess, sorry.
I'm quite experienced with PHP but it's not easy for me to copy/paste IfContentNode.php – I'd really appreciate a step by step tutorial. The docs unfortunately don't explain it well enough for me :(
- Infanticide0
- Member | 112
@bernhard
I've never done a Latte extension, it will probably need some tuning. Still
don't understand it completely.
Hope this helps.
template:
output:
- David Grudl
- Nette Core | 8249
I think it is enough to copy the IfContentNode class and replace
rtrim(ob_get_flush())
with rtrim(strip_tags(ob_get_flush()))