Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Grav removes Strings in <> in code

Started by ne 7 years ago · 1 replies · 462 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 Jerry Hunt, 4 days ago
2 128 20 hours ago
General · by pamtbaau, 1 day ago
1 89 1 day ago
General · by Andy Miller, 2 days ago
0 73 2 days ago
General · by Marcel, 12 months ago
6 382 5 days ago
General · by Duc , 6 days ago
3 69 6 days ago