In a text block, I highlight the initial visually.
The first letter in the text block is read out with short(1,'').
The first letter is to be subtracted from the remaining text.
I do this with <?= Str::substr($textblock->kt(),1) ?>
Unfortunately, html tags interfere with this, as they are also counted.
How can I ensure that html tags are ignored?
Is there a suitable field method?
I have never worked with the Kirbytext helper kirbytext($string) and am therefore not familiar with how it works. Therefore, I apologize for my lack of knowledge.
Unfortunately, HTML tags are still displayed in the initial text, but no longer in the subsequent text, where I used Str::afterStart instead of Str::substr.
Text: <p><strong>Leben und Schönheit, Bios und Ästhetik</strong> – die Verbindung von natürlichen Inhaltsstoffen, modernster Forschung und Leidenschaft für die Schönheit bestimmen seit dem ersten…
Yes, that’s right. I used a writer field. I have now used a textarea field:
text:
type: textarea
buttons:
- bold
- italic
label: Text
… but the result is unfortunately unchanged, with the following output.
Shouldn’t all HTML tags be removed with the function “->kt()->inline()”?
You are still passing the rendered Html to Str::short(), while you need to pass just the value of the field before applying kirbytext in each case, see above.
Note that if your users put html into the field or use a kirbytag at the beginning of a line, this will still fail and I don’t know if there is a good way to account for all edge cases without breaking stuff
Many thanks for the explanations of the modified code.
It looks logical and tidy.
However, the output is empty
For a better understanding, I will list all areas again here:
Blueprint with textarea-field:
text:
type: textarea
buttons:
- bold
- italic
label: Text
.txt-file:
----
Text:
**Leben und Schönheit, Bios und Ästhetik** – die Verbindung von natürlichen Inhaltsstoffen, modernster Forschung und Leidenschaft für die Schönheit bestimmen seit dem ersten Tag die Philosophie.
Höchste Qualität ist nicht einfach eine Möglichkeit, sie ist die Voraussetzung. Sie ist die Wurzel – für die Culture Of Total Beauty.
----
Note that if your users put html into the field or use a kirbytag at the beginning of a line, this will still fail and I don’t know if there is a good way to account for all edge cases without breaking stuff
If Markdown and HTML tags make things too complex, I’d rather make a compromise and do without text formatting. However, my output only works with this code: