Rendering problems with div in a KirbyTag (in a block)
When I use <div> in a created KirbyTag (like this wikipedia-tag example), the html output of a block will change from using <p> to using <br/> from that point on. This causes problems like links dissapearing and markup problems based on my CSS.
codesnippet from the wikipedia example
The example will give me no problems: return '<a href="/">Wikipedia</a>'; Also <span> is allright for me to use.
but return '<div>Wikipedia</div>';
will render everything after the KirbyTag a different way.
Instead of using <p> for every line, it will use <br/> from that point on.
Question
Am I doing something wrong, or is this a known thing?
context
In the template I use <?= $block->textfield()->kt() ?>. And the KirbyTag is rendered without problems. Only what comes after the KirbyTag is not rendered properly.
For the blocks I am using code that resembles the Block factory examples
Why don’t you use a markdown block if you want to use Kirbytags?
A writer field is not really intended to support Kirbytags.
Having said that, I did a quick test and cannot reproduce the issue, maybe you can post the exact content of your alinea field? Is it already stored wrong or is just the output wrong?
I am a beginner and have not come across this, so I looked it up just now:
Could you tell me how to change my alinea: into a markdown block?
I have difficulty changing the example I found here into something that resembles my field.
But also:
I first pasted the existing text directly into a newly created block: no change.
Then I pasted the text via my editor to remove all the markup: It worked!
So, when I copied the old text the first time I was not aware that all the markup was also copied and pasted into the new block with all the <br> still in there.
Now I know.
Thank you so much for your help in solving this. Also I will read more on the markup block although it seems I couldn’t use it here, because of the other fields.
You could simply replace the writer field in your custom block with a textarea field. This would make sense when you keep running into issues with the writer field. Probably depends on the types of Kirbytags you want to use.
Thanks!
I have now changed every writer field in my different types of blocks.
But I have another problem, this time with the edit-sidebar.
Should I now also change <k-writer .. /> definitions in the index.js of the block plugin
into: <k-textarea-field ... /> ?
Because on the Panel, the side editor reacts strange:
I cannot edit without the cursor jumping to the last character.
Thank you soo much!
I have used the type: textarea and <k-input ..> combination.
And so far it looks to work very good! I’m relieved.
I have been struggling with this for some time now. I also now know why I used the writer field: I followed the example from the block-factory as I mentioned above. And there were only text fields with type: writer in there.
And thank you for the link to the source code, now I have a better understanding how to get examples of use. I would never been able to find that by myself.