How to use it to template a variable in url?
bronze1man opened this issue · 1 comments
bronze1man commented
I have following php template, I am trying to translate to gorazor template.
<img src="/public/image/login-image-<?php echo rand(1,5);?>.jpg" alt="Login Full Background" class="full-bg animation-pulseSlow">
I have tried this:
@{
import (
"github.com/bronze1man/kmg/kmgRand"
)
}
<img src="/public/image/login-image-@kmgRand.IntBetween(0,5).jpg" alt="Login Full Background" class="full-bg animation-pulseSlow">
It will product:
package Tpl
import (
"bytes"
"github.com/bronze1man/kmg/kmgRand"
"github.com/sipin/gorazor/gorazor"
)
func AdminLoginPage() string {
var _buffer bytes.Buffer
_buffer.WriteString("\n<img src=\"/public/image/login-image-")
_buffer.WriteString(gorazor.HTMLEscape(kmgRand.IntBetween(0, 5).jpg))
_buffer.WriteString("\" alt=\"Login Full Background\" class=\"full-bg animation-pulseSlow\">")
return _buffer.String()
}
bronze1man commented
Sorry for disturbing you.
I have fixed it with following code:
@{
import (
"github.com/bronze1man/kmg/kmgRand"
)
}
<img src="/public/image/login-image-@(kmgRand.IntBetween(0,5)).jpg" alt="Login Full Background" class="full-bg animation-pulseSlow">