CSS and JavaScript
Dracory makes it easy to include CSS and JavaScript in your pages. You can include stylesheets and scripts from CDNs or add inline styles and scripts directly in your controllers.
Including CSS
// Add stylesheet URLs
webpage := layouts.NewUserLayout(r, layouts.Options{
// ...
StyleURLs: []string{
"https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css",
},
})
// Add inline styles
webpage := layouts.NewUserLayout(r, layouts.Options{
// ...
Styles: []string{
`.my-class { color: blue; }`,
},
})
Including JavaScript
// Add script URLs
webpage := layouts.NewUserLayout(r, layouts.Options{
// ...
ScriptURLs: []string{
"https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js",
},
})
// Add inline scripts
webpage := layouts.NewUserLayout(r, layouts.Options{
// ...
Scripts: []string{
`document.addEventListener('DOMContentLoaded', function() {
console.log('Page loaded');
});`,
},
})