Como empezar
- Instalar Buffalo
- Generando Nuevo Proyecto
- Estructura de Directorio
- Configuración
- Integracion de Herramientas
Gestión de Peticiones
- Enrutamiento
- Controlador de Acciones
- Recursos
- Contexto
- Vinculación de Peticiones
- Middleware
- Manejo de Errores
- Sesiones
- Cookies
Frontend
- Renderizado
- Plantillas
- Diseños
- Parciales
- Helpers
- Helpers Personalizados
- Mensajes Flash
- Formularios
- Recursos
Base de datos
- Iniciando con Pop
- Soda CLI
- Configuración de base de datos
- Integración con Buffalo
- Modelos
- Generadores
- Migraciones
- Fizz
- Mutaciones
- Consultas
- Consultas SQL nativo
- Callbacks
- Scoping
- Asociaciones y Relaciones
- Asociaciones Uno a Uno
- Asociaciones Uno a Muchos
Guías
- Aplicaciones API
- Carga de archivos
- Ejecuciones en segundo plano
- Mailers
- Tareas
- Plugins
- Local Authentication
- Third Party Authentication
- Eventos
- Go Modules
- Localización
- Registros
- Motores de Plantillas
- Pruebas
- Videos
Deploy
Diseños
Frontend
Diseño#
Este documento solo aplica cuando se usa github.com/gobuffalo/buffalo/render.
Consulta github.com/gobuffalo/plush para más detalles sobre el paquete de plantillas.
Usando un diseño estándar#
Es bastante común querer usar el mismo diseño en la mayoria, si no en toda la aplicación. Al crear un nuevo render.Engine
the se puede establecer la propiedad HTMLLayout
a un archivo que será usado automáticamente por la función render.HTML
.
actions/render.go
templates/application.plush.html
templates/hello.plush.html
actions/hello.go
Output
var r *render.Engine
func init() {
r = render.New(render.Options{
// ...
HTMLLayout: "application.plush.html",
// ...
})
}
<html>
<head>
<title>My App</title>
</head>
<body>
<div id="main">
<%= yield %>
</div>
</body>
</html>
<h1>Hello!!</h1>
func Hello(c buffalo.Context) error {
return c.Render(http.StatusOK, r.HTML("hello.html"))
}
<html>
<head>
<title>My App</title>
</head>
<body>
<div id="main">
<h1>Hello!!</h1>
</div>
</body>
</html>
Usando un diseño personalizado#
A veces, en ciertas peticiones, se necesita un diseño diferente. Este diseó alternativo se puede pasar como segundo parámetro al render.HTML
.
Los diseños personalizados NO funcionan con
render.Auto
.
actions/render.go
templates/custom.plush.html
templates/hello.plush.html
actions/hello.go
Output
var r *render.Engine
func init() {
r = render.New(render.Options{
// ...
HTMLLayout: "application.plush.html", // You can realize that render continues using the application.plush.html
// ...
})
}
<html>
<head>
<title>My Custom Layout</title>
</head>
<body>
<div id="main">
<%= yield %>
</div>
</body>
</html>
<h1>Hello!!</h1>
func Hello(c buffalo.Context) error {
return c.Render(http.StatusOK, r.HTML("hello.plush.html", "custom.plush.html"))
}
<html>
<head>
<title>My Custom Layout</title>
</head>
<body>
<div id="main">
<h1>Hello!!</h1>
</div>
</body>
</html>