I am migrating an old site into Kirby and unfortunately I don’t have time to reformat everything, so I am having to put HTML straight into the Text field of my pages. Most of the time it works fine, but on rare occasions I find that if I edit the HTML the page ends up dumping copies the raw html into code and pre elements on the page! Very strange. I am filtering it through kirbytext()
, and I assume something is triggering it to do these code and pre blocks, but I am not sure what. I know it must have something to do with line breaks because if I merge the html onto one line the problem goes away…
My txt files currently have the text field like this:
Text:
<html goes here>
And like I said, that works fine as long as I don’t try to edit it. I tried Text: >
and Text: |
, but those didn’t help.
1 Like
Ah yes, removing the indenting fixes it. But the weird thing is, the html has indenting to begin with. So maybe it has to do with the fact that I am on Windows and maybe I am turning \n line breaks into \r\n? That plus the Markdown indentation thing? Oh well, I guess I will learn to live with it, unless you know of some convenient way to turn off markdown just for this field, while still being able to output it as real html code, and not escaped, which is what happens if I don’t run it through kirbytext().
Have you tried to output it with the html()
method instead of kirbytext()
?
I didn’t know about html()
! It sounds like what I want, but for some reason, when I try it, I still get the crazy pre and code elements.
Hm, then you could try to use a Kirbytext pre-filter to get rid of the identations before the text is parsed.
Doh! Sorry, there was a typo in my code which meant that the html()
helper wasn’t actually doing it’s thing. I am glad the world actually makes sense again.
I just had that problem myself when creating a custom kirbytext tag. It was the indented text that made the code/pre things. I solved it like this:
return str_replace( "\t", "", $output );
Can you give us the full code and tell us where to place it?
Thanks a lot
One way is to write it like this (untested):
$field_data = $page->some_field();
$field_data = str_replace( "\t", "", $field_data );
$field_data = kirbytext( $field_data );
echo $field_data;