Cannot escape html using shortcode within a textarea

I am having trouble escaping HTML using shortcode associated with a textaera. An example (for the shortcode) is given below:

	<textarea>{{printf "<" | safeHTML}}
	</textarea> 
	
	{{printf "<" | safeHTML}}

However, the “<” in the textarea changed to “&lt;” in the rendered html. Interestingly, the “<” not in the textarea behaved as expected.

	<textarea>&lt;
	</textarea> 
	
	<

I wonder if there is a way not to change “<” to “&lt;”. Any suggestion is appreciated.

I am using hugo version v0.80.0. I am completely new to this board. Let me know if I can provide any other information. Thanks a lot.

I’m not convinced there’s a good reason to do what you are trying to do, but this will do it for you:

{{ printf "<textarea><</textarea>" | safeHTML }}

Thanks! Not sure why, but it worked.

I am trying to generate PHP code blocks. Eventually, I had to do something like this:

{{printf "<textarea" | safeHTML}} id='{{ .Get "id" }}'  
	{{printf "><?php" | safeHTML}} 
	echo "OK";?>
	</textarea>

I knew it didn’t look nice, but it generated the correct code I want now.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.