Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Grav removes Strings in <> in code

Started by ne 7 years ago · 1 replies · 685 views
7 years ago

Hi.
I want to use the Kotlin Playground on my site. But I have a problem with Kotlin code in <> because it gets stripped out.

For example the file with content:

41%402x|690x258

gets translated into:

object HandshakeCalculator {
fun calculateHandshake(number: Int): List {
val binaryToSignal = Signal.values().asList()
val binaryString = number.toString(2)
var result = mutableListOf()
binaryString.reversed().forEachIndexed { index, item ->
if (item == '1') {
if (index < binaryToSignal.size) {
result.add(binaryToSignal[index])
}
}
}
return if (binaryString.reversed().getOrNull(4) == '1') result.reversed() else result
}
}

-> The <Signal> String is removed. How can I teach Grav that it handles the code as it is and does NOT filter anything in it?

last edited 07/24/19 by ne
7 years ago

Inserting Javascript code in the page content is not allowed by Grav.

The easiest way is to use the Assets Plugin. You'll find it in the Grav Plugins Download section of the Grav website. Or if you are using the Admin Plugin you can add that plugin by clicking the Add button under Plugins in the Admin panel.

Once installed you can add the external Javascript file like this:

TXT
{assets:js order:10}
https://unpkg.com/kotlin-playground...
{/assets}

and your Javascript code inline as you tried but then like this:

TXT
{assets:inline_js}
object HandshakeCalculator {
      fun... 
{/assets}

If you want to understand how to use assets like Javascript code and CSS stylesheets in theme templates and without using the Assets Plugin, you'll want to read the docs about Themes and specifically about Adding Assets.

I hope this helps.

Suggested topics

Topic Participants Replies Views Activity
General · by themetman, 1 day ago
2 41 18 hours ago
General · by Hanns Mattes, 1 week ago
0 121 1 week ago
General · by Karmalakas, 1 week ago
2 185 1 week ago
General · by Hanns Mattes, 3 weeks ago
0 235 3 weeks ago
General · by Dima, 4 weeks ago
1 211 4 weeks ago