jczic / MicroWebSrv

A micro HTTP Web server that supports WebSockets, html/python language templating and routing handlers, for MicroPython (used on Pycom modules & ESP32)
https://github.com/jczic/MicroWebSrv
MIT License
641 stars 116 forks source link

Added template include command #17

Closed JK-de closed 6 years ago

JK-de commented 6 years ago

In most web pages parts like header, navigation bar and scripts are repeated in all html files. Wirh the command {{ include <filename> }} you can include/insert the content of the given file at the position of the command. So, the repeated content must only present once in the includes file.

The include file is opened in the same dir as the pyhtml file. The file can also content {{}}-commands.

A pyhtml file can look like:

<html>
    <head>
        {{ include head.thtml }}
    </head>
    <body>
        {{ include navbar.thtml }}

        <h1>Unique content of this html page</h1>

        {{ include script.thtml }}
    </body>
</html>

And the corresponding 'head.thtml' can be:

<meta charset="UTF-8" />
<title>{{ title }}</title>
<link rel="stylesheet" href="style.css" />

Note: the file extention 'thtml' is just a suggestion

jczic commented 6 years ago

Excellent!, I'will merge your patch and add in help text as soon as. :)

2018-02-17 7:47 GMT+01:00 Jochen Krapf notifications@github.com:

In most web pages parts like header, navigation bar and scripts are repeated in all html files. Wirh the command {{ include }} you can include/insert the content of the given file at the position of the command. So, the repeated content must only present once in the includes file name.

A pyhtml file can look like:

{{ include head.thtml }} {{ include navbar.thtml }}

Unique content of this html page

{{ include script.thtml }}

And the corresponding 'head.thtml' can be:

Page de test MicroWebSrv

Note: the file extention 'thtml' is just a suggestion

You can view, comment on, or merge this pull request online at:

https://github.com/jczic/MicroWebSrv/pull/17 Commit Summary

  • Added template include command

File Changes

Patch Links:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jczic/MicroWebSrv/pull/17, or mute the thread https://github.com/notifications/unsubscribe-auth/AAegLF3bS3nh0xtZZ5c8Bu7_cPd6k3u4ks5tVnYegaJpZM4SJN39 .

--

Sincèrement,