bookings's People
Forkers
tuanden0 sn00pyd0g alyragab darkside1809 ricardoltm sunliho nurtai00 neeravarora abiodunicode dhakobyan-clgx maxshabl mdevries6996 muktar11 elx123 didik78 ddoffy lazyspell dhhanush xmonader zhecho mfcaballero devsendjin mcnguyen senamix kurapika-yuhang jackgris tommitoan david0z imprimph geyungjenbookings's Issues
no such template "base"
Even after parsing the *.layout.html
as you mentioned in your udemy tutorial, I am still getting the following error.
error occurred while parsing template: html/template:home.page.html:1:11: no such template "base"
render.go
package render
import (
"fmt"
"html/template"
"net/http"
"path/filepath"
)
var functions = template.FuncMap{}
// RenderTemplate renders a template
func RenderTemplate(w http.ResponseWriter, tmpl string) {
templateCache, err := RenderTemplateTest(w)
if err != nil {
fmt.Println("error getting template cache: ", err)
}
fmt.Println("actual value:", templateCache[tmpl])
parsedTemplate, _ := template.ParseFiles("./templates/" + tmpl)
err = parsedTemplate.Execute(w, nil)
if err != nil {
fmt.Println("error occurred while parsing template:", err)
return
}
}
// RenderTemplateTest renders all template
func RenderTemplateTest(w http.ResponseWriter) (map[string]*template.Template, error) {
myCache := map[string]*template.Template{}
pages, err := filepath.Glob("./templates/*.page.html")
if err != nil {
return myCache, err
}
for _, page := range pages {
name := filepath.Base(page)
fmt.Println("Page is currently :", name)
ts, err := template.New(name).Funcs(functions).ParseFiles(page)
fmt.Println("ts ==", ts)
if err != nil {
return myCache, err
}
matches, err := filepath.Glob("./templates/*.layout.html")
fmt.Println(matches)
if err != nil {
return myCache, err
}
if len(matches) > 0 {
ts, err = template.ParseGlob("./templates/*.layout.html")
fmt.Println("Inside len(matches)", ts)
if err != nil {
return myCache, err
}
}
myCache[name] = ts
}
return myCache, nil
}
base.layout.html
{{define "base"}}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home!</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">
{{block "css" .}}
{{end}}
</head>
<body>
{{block "content" .}}
{{end}}
{{block "js" .}}
{{end}}
</body>
</html>
{{end}}
home.page.html
{{template "base" .}}
{{define "content"}}
<div class="container">
<div class="row">
<div class="col">
<h1>This is the home page!!</h1>
<p>This is some text!!</p>
</div>
</div>
</div>
{{end}}
main.go
package main
import (
"fmt"
"net/http"
"github.com/MukulLatiyan/go-project/pkg/handlers"
)
const portNumber = ":8090"
func main() {
http.HandleFunc("/home", handlers.Home)
http.HandleFunc("/about", handlers.About)
fmt.Println("Server has started running on:", portNumber)
_ = http.ListenAndServe(portNumber, nil)
}
navigation shortcut in goland
Hello, I'm one of your student from your Udemy course(Building modern web applications in Go), Which shortcut do you use to open this popup?!
Theme and Font
Hello, Trevor, I'm watching your course and I want to ask what the theme and the font you use, thank you for the answer.
error in go template variable inside javascript tag
Adding go template variable inside Javascript tag getting parsing error.
bookings/templates/base.layout.tmpl
Line 156 in 926f442
I'm using go1.22.2 linux/amd64.
I have resolved the issue by modifying the javascript code.
<script>
function notify(msg, msgType) {
notie.alert({
type: msgType,
text: msg,
})
}
let error = "{{.Error}}"
if (error !== "") {
notify(error, "error");
}
let flash = "{{.Flash}}"
if (flash !== "") {
notify(flash, "success");
}
let warning = "{{.Warning}}"
if (warning !== "") {
notify(warning, "warning");
}
</script>
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.