GithubHelp home page GithubHelp logo

Processing layouts about fullmoon HOT 6 CLOSED

pkulchenko avatar pkulchenko commented on June 6, 2024
Processing layouts

from fullmoon.

Comments (6)

pkulchenko avatar pkulchenko commented on June 6, 2024

@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.

johnmuhl avatar johnmuhl commented on June 6, 2024

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.

pkulchenko avatar pkulchenko commented on June 6, 2024

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.

johnmuhl avatar johnmuhl commented on June 6, 2024

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.

pkulchenko avatar pkulchenko commented on June 6, 2024

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.

pkulchenko avatar pkulchenko commented on June 6, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.