commit a3bc2515b23de27cce9bc5f031cb84e59ad4529d Author: Dita Aji Pratama Date: Sat Sep 26 15:23:50 2026 +0700 First commit diff --git a/costapy-template-create.md b/costapy-template-create.md new file mode 100644 index 0000000..97ff861 --- /dev/null +++ b/costapy-template-create.md @@ -0,0 +1,95 @@ +# CostaPy / Template / Create + +Here is the guide about how to create a template for costapy. + +What you need to prepare: +- template name +- static file and directory +- raw HTML template +- part or component that you want to create + +## Create a directory +- make a directory with your template name `mkdir learn` +- go to a template directory `cd learn` +- then `learn` is your template directory + +## Routing a static file + +create `static` directory inside the template directory. + +create `main.py` inside the template directory and add a static list +```python +static = [ + { + "route" : "/templates/learn/css/", + "root" : "./templates/learn/static/css" + } +] +``` + +then you can manage your file on there. For example, put `style.css` on `static/css`. + +## Separate the part or component from the raw HTML template + +create `html` directory inside the template directory. and place your raw `index.html` in here. + +create `main.py` inside the template directory and set the template parts or components +```python +from core import html + +def main(dir, page): + html_template = html.main.get_html("templates/learn/html") + html_page = html.main.get_html(dir) + return { + "index" : html_template [ "index.html" ], + "navbar" : html_template [ "navbar.html" ], + "footer" : html_template [ "footer.html" ], + "container" : html_page [f"{page}.html" ] + } +``` + +adjust and separate the code into a modular file. For example, here I separate `navbar` and `footer` into a modular file. Use python mako template. + +`index.html` +```python + + + + + + + ${title} + + + +
+

${header}

+
+ ${navbar} +
+ ${container} +
+ ${footer} + + +``` + +`navbar.html` +```python + +``` + +`footer.html` +```python + +``` diff --git a/costapy.md b/costapy.md new file mode 100644 index 0000000..266662a --- /dev/null +++ b/costapy.md @@ -0,0 +1,6 @@ +# CostaPy + +Here is the instruction list that you can call. + +Templating +- `costapy-template-create.md` Create a template