I think for a simple website, especially one with spartenweb or zero JS principles, a language with an architecture like PHP or ASP/ASPX fits well, where you just write HTML and server side code in the same file, and you navigate to that file from your URL to load it. For example, wwwroot/path/to/page.php on the server corresponds to https://example.com/path/to/page.php

Problem is, both PHP and ASP are pretty terrible languages, and ASP(X) has the additional dealbreaker of not being open source and only running on Windows servers, so I don’t really want to use any of them (I’ve tried all three), so are there any better web languages or web frameworks that does something similar?

  • @vitaminka
    link
    42 years ago

    check out dioxus, it’s very similar to react, but uses rust instead or js, it also uses a JSX-like syntax, and although there isn’t an automatic direct mapping between files and webpages, they give a router with which you can easily make it work that way 🤷‍♀️

  • Mad
    link
    fedilink
    4
    edit-2
    2 years ago

    try rocket, the rust framework. it’s fast, simple and powerful. it doesn’t have the directory structure thing you want by default, but there’s nothing stopping you from using it like that. there’s not really any boilerplate so each file would just be a function that returns your html which is generated by server-side code (or is static). it also lets you handle dynamic routes and url queries VERY cleanly. you’d have to write your html in a string if you used the default stuff, but you can use typed_html, a small library that provides a macro (rust macros are not your usual evil macros) for writing html a bit more naturally. or you can use rocket’s built-in template engine support (i think it’s just tera and handlebars by default, i couldn’t see any others mentioned), though i haven’t used that so i can’t say how good it is.

    rocket is a great way to do nojs sites, because it’s built for APIs and not “modern” web pages, and it’s made so that you barely notice it even exists, so you can just write code/html like normal. the best thing is how it lets you respond to input, through very powerful dynamic URLs, through queries/forms, through static URLs, or through a combination of all of those

    (i love how the other guy wrote a one sentence recommendation while i wrote an essay. sry lol)

  • @electrodynamica@mander.xyz
    link
    fedilink
    32 years ago

    What’s interesting is that even though code is mixed with html by design in PHP, ultimately a lot of frameworks tend to create a whole other layer of templates, complete with pseudocode like loops and conditionals. If you’re going to do that, you might as well just do CGI methinks.

    Mixing code and page layout isn’t the solution it appears to be. Another fun approach is to use sophisticated XSL templates to generate the HTML from XML data, and CSS to style it.

  • ☆ Yσɠƚԋσʂ ☆
    link
    32 years ago

    Hiccup with Clojure works this way, and since Clojure uses s-expression syntax it’s natural to express HTML directly using native language data structures without any need for DSLs.

    For small sites, you can run them on Babashka interpreter as seen here without needing the JVM.

  • overflow
    link
    32 years ago

    check out java server pages

  • @Aarkon@feddit.de
    link
    fedilink
    32 years ago

    Depending on what you want to do and how much server side the server side code really needs to be, I’d suggest you take a look at:

    • Django: Full blown Python web application framework with database migrations and a lot more of bells and whistles
    • elm pages: Static page generator around the elm programming language, where you can bake a lot of things into a (after compilation) static html page but still have a very powerful and flexible language for dynamic content at your fingertips
  • Helix 🧬
    link
    fedilink
    0
    edit-2
    2 years ago

    This is a bad idea programming-wise, since you want to separate templates and output due to DRY principle, Separation of Concerns, maybe the MVC programming paradigms and general code cleanliness.

    If you do this wrong with dynamic pages, you open up issues with code injection. At the very least, your code will be hard to read.

    • @Aarkon@feddit.de
      link
      fedilink
      32 years ago

      Code injection is an issue everywhere as soon as you leave the realm of purely static html. That’s why I’d recommend to use a framework to do this instead of sanitizing every possible input yourself.

      DRY, SoC etc. are all sane principles, but that’s not to say that you can’t have an html template and some dynamic language in the same file. You’d only have to think differently about encapsulation and code reuse. Components are a popular pattern these days, exposing functionality that you want to have in multiple places across your page.

      • Helix 🧬
        link
        fedilink
        22 years ago

        Well said. Of course this is not a black and white issue. Some code and design can be mixed but the PHP way of allowing HTML with server side includes, sometimes even based on form input, is just a recipe for disaster. That’s actually why Cake and Laravel don’t even really allow this, or at least make it super hard to do.