Comments (6)
@johnmuhl, I'm curious as to what you did and what you were trying to achieve. It's definitely supported, but the support may not be exactly the same as some other frameworks/toolkits do this. I haven't documented it yet, as I wasn't sure if anything else may be needed, so the API may have to change, but so far it looks like what's there already should be sufficient.
If you can describe your example (and the solution you came up with) maybe I can help to see how it can be simplified or what elements may need to be incorporated into the framework. Thanks!
from fullmoon.
Most pages all have the same header/footer and just the content changes. A few pages need custom layouts. The layouts just need a single "outlet" where the page specific template is rendered.
-- .init.lua
fm.setTemplate({ "/templates/", fmt = "fmt" })
fm.serveTemplate = function (tmpl, opts, layout)
layout = layout or "_layout"
return FM.serveContent(layout, {
tmpl = tmpl,
opts = opts,
})
end
<!-- _layout.fmt -->
<html>
<head>...</head>
<body>
<nav>...</nav>
<header>...</header>
{%= render(tmpl, opts) %}
<footer>...</footer>
</body>
</html>
Then I call fm.serveTemplate("profile", {...})
instead of fm.serveContent("profile", {...})
.
from fullmoon.
Yes, you can definitely do that and it's going to work. Despite using Perl for 15+ years (or maybe because of it), I'm not a big fan of implicit behaviors/magic, so in a situation like yours, I'd use the same template and just call it exactly as you do, but use it explicitly: fm.serveContent(layout, {tmpl = tmpl, opts = opts})
.
You can definitely use the method you're showing, but I'd like to encourage more explicit usage, so will likely keep things are they are. I do need to update the documentation though (as you see the templates are a bit under-documented), so am going to cover this as one of the cases. I'll reference this ticket when the documentation is updated.
from fullmoon.
I started with the serveContent
version you show but it felt a little off. Knowing it's the preferred way I'll switch back and see if it grows on me.
from fullmoon.
Knowing it's the preferred way I'll switch back and see if it grows on me.
Sounds good; please let me know if this still doesn't sit right with you after some further usage.
from fullmoon.
For those looking at this ticket for layout-related information, I added blocks and detailed template documentation, including layout handling: https://github.com/pkulchenko/fullmoon#using-layouts-and-blocks.
@johnmuhl, let me know if you think something is missing or needs a better explanation. Thanks!
from fullmoon.
Related Issues (20)
- hand over route back to the redbean core if no matching fullmoon route HOT 3
- Uncertain how to obtain query parameters HOT 6
- Any CRUD example for using SQLite? HOT 2
- Any help with DNS/virtual hosting/ip address? HOT 3
- Support for multipart/form-data to allow uploading files HOT 10
- serveRedirect parameter order HOT 1
- [Suggestion] Disable Listing HOT 4
- [Suggestion] Built-in DDOS Protection HOT 3
- multipart form validation HOT 4
- using booleans in oneof rules HOT 2
- In the instructions: "curl -o redbean.com https://justine.lol/redbean/redbean-latest.com" does not work HOT 3
- makeStorage support for in memory database HOT 4
- Does setTemplate support fmg table in lua code directly HOT 9
- Provide DB synchronization HOT 1
- [help] can not load techbench module ? HOT 13
- Feature request: form input validation HOT 13
- Windows Defender Virus Detected HOT 4
- Custom template engines? HOT 4
- Getting the body of the request HOT 3
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 fullmoon.