Comments (8)
The package use just the template syntaxe for generating html. Because it handle all the logic to translate component to html, you can't do all the feature that the standard template package do.
A solution for that would be to implement the TemplateFuncMapper interface => https://github.com/murlokswarm/app/blob/master/component.go#L39
you could do something like:
func (c *YourComponent) FuncMaps() template.FuncMap {
return template.FuncMap{
"add": func(x, y int) int {
return x + y
},
}
}
func (c *YourComponent) Render() string {
return `
<div>
x + 1 = {{add .X 1}}
</div>
`
}
But honestly, I think your html should just contain your interface description. This kind of operation should be done in go code.
from go-app.
I tested your suggestions.
In the returned html string of Render(), I have the following code.
{{range $i, $row := .Board}}
{{range $j, $elem := $row}}
{{if eq $elem 1}}
<circle cx="{{add 15 $i}}" cy="{{add 15 $j}}" r="12" fill="url(#grad)" />
{{else if eq $elem 2}}
<circle cx="{add 15 $i}}" cy="{{add 15 $j}}" r="12" fill="white" />
{{end}}
{{end}}
{{end}}
And in the go part, I added the following function:
func (g *Gobang) FuncMaps() template.FuncMap {
return template.FuncMap{
"add": func(x, y int) int {
return x + y
},
}
}
I can build it. But when I run it, I got the error:
panic: template: Render:65: function "add" not defined
How could that be?
from go-app.
from go-app.
Yes. I used html/template before. Now I changed to text/html, and "add" can be done normally.
However, when I want to do nested calculations, e.g. 15 + 30 * {{$i}}, the code below doesn't work.
In html:
{{add 15 {{multi 30 $i}}}}
In go:
func (g *Gobang) FuncMaps() template.FuncMap {
return template.FuncMap{
"add": func(x, y int) int {
return x + y
},
"multi": func(x, y int) int {
return x * y
},
}
}
The error is:
panic: template: Render:68: unexpected "{" in operand
So what should I do if I want to do add and multiply at the same time?
from go-app.
did you tried, {{add 15 multi 30 $i}}
?
Also I dont know if go template accept $i
.
from go-app.
I got the error:
ERROR 2017/12/02 23:48:45 app.go:57: unable to render *main.Gobang: template: Render:68:23: executing "Render" at <add>: wrong number of args for add: want 2 got 4
So I think it doesn't work.
I tested with {{add 15 $i}} and {{multi 15 $i}}, they work. So I think go template can accept $i.
from go-app.
{{add 15 (multi 30 $i)}}
=> https://golang.org/pkg/text/template/#hdr-Examples
from go-app.
Thanks!!!!! I fixed it.
Have a good day! :)
from go-app.
Related Issues (20)
- debugging terminal errors HOT 6
- problem with page render HOT 3
- [Question] What's the best way to handle form submission data? HOT 29
- Some content double rendering in the browser HOT 12
- How to force ctx.Navigate() to open target in a new Tab HOT 1
- I think there is serious bug with `ctx.PreventUpdate()` now HOT 5
- Unable to set css class for svg custom elements
- Is go-app still an active project? HOT 5
- Is this dead? HOT 10
- How to make a cute CRUD table component HOT 17
- Load static files to Canvas HOT 2
- Support for React? HOT 3
- Global css variables does not get set HOT 3
- New name for go-app? HOT 1
- V10 property update issue HOT 3
- Makes the generated HTML available without having to mount the elements. HOT 2
- Modify tag building so that we can avoid calling Body() HOT 4
- Signal based change detection HOT 2
- Render calls before OnMount HOT 1
- debug go-app in nowasm HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-app.