<b>REGISTER</b>

GFX-Sector - Scripte & Downloads


 
GFX-Sector » Coding Area » Scripte & Downloads » [Python3] Simple Template System » Hello Guest [Login|Register]
Last Post | First Unread Post Print Page | Recommend to a Friend | Add Thread to Favorites

Scripte & Downloads

Du hast ein tolles Script gefunden oder geschrieben und möchtest es mit uns teilen? Hier ist der richtige Ort dazu.
Post New Thread Post Reply

[Python3] Simple Template System

     Deutsche Version  English version
Author
Post « Previous Thread | Next Thread »

quantum quantum is a male
Pfadfinder

Spender


Avatar von quantum

Registration Date: 29.12.2008
Posts: 721
Deviantart: xcracx

Spacer
[Python3] Simple Template System

[Python3] Simple Template System

      

Hier mal eins meiner kleinen Module.

Eigentlich recht nützlich, da es nicht so "fett" wie die built-in Module ist. Simpel halt.

Download:
http://script.pcriot.com/dl/Template.py

Paste:
http://pastebin.revalc.de/view.php?ID=110

Beschreibung/Anleitung:
In der Template-Datei werden gewisse Platzhalter notiert. (eingeschlossen von {})

Beispiel:
templates/head.html
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
<!DOCTYPE HTML>
<html lang="{lang}">
<head>
    <meta charset="{charset}">
    <title>{title}</title>
</head>
<body>
<div id="main_wrap">
<header>
<h1>{title}</h1>
<h2>{sub_title}</h2>
    <ul>
        {navigation}
    </ul>
</header>
    <div id="content">
<article id="main_article">


Die Template-Datei hat nun folgende Keys:
lang, charset, title, sub_title und navigation

Es gibt nun zwei Möglichkeiten, die Platzhalter zu ersetzen:

Einzelnd:
Für jeden Key der Datei die Funktion setkey() aufrufen:

code:
1:
2:
3:
4:
templ = Template('templates/head.html')

templ.setkey('title', 'YourTitleHere')


Gesamt:
Oder direkt die ganzen Keys in einem Wörterbuch notieren und die Funktion setallkeys() aufrufen:
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
templ = Template('templates/head.html')

dict = {
	'lang': 'de',
	'charset': 'utf-8',
	'title': 'YourTitle',
	'sub_title': 'YourSubTitle',
	'navigation': '<li><a href="#">Home</a></li>'
}

templ.setallkeys(dict)


Um den Code nun als ganzes zu bekommen:
entweder:
code:
1:
templ.getcode()

oder
code:
1:
templ.code


Ausgabe:
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
<!DOCTYPE HTML>
<html lang="de">
<head>
    <meta charset="utf-8">
    <title>YourTitle</title>
</head>
<body>
<div id="main_wrap">
<header>
    <h1>YourTitle</h1>
    <h2>YourSubTitle</h2>
    <ul>
        <li><a href="#">Home</a></li>
</ul>
</header>
    <div id="content">
<article id="main_article">


Sollte es irgendetwas geben, was euch stört, wo ihr Hilfe benötigt oder sonstiges, sagt einfach bescheid Wink

lg



Thanks for this thread by the author

Until now 2 users have thanked


[Python3] Simple Template System 11.06.2010 22:22 quantum is offline Homepage of quantum Search for Posts by quantum

ProWeb ProWeb is a male
Buntstiftmaler


Avatar von ProWeb

Registration Date: 15.04.2010
Posts: 94
Location: Ludwigshafen
Program: Photoshop CS4

Spacer
      

Danke dir smile

[Python3] Simple Template System 20.07.2010 00:51 ProWeb is offline Homepage of ProWeb Search for Posts by ProWeb
 
Spacer
   
GFX-Sector
unregistered


 hat kein Avatar


Spacer

Have you enjoyed this topic?


If you were enjoying this post and if you keen on reading more interesting stuff then do not hesitate to complete the free sign up.

After the free registration you will gain access to all areas and you will be able to communicate with other artists from all over the world.

In addition you will benefit from our Photoshop and coding section as well as from our huge (hundreds of gigabytes) free resource section where you can find everything you will need to be a successful (web) designer/artist.

Sign up now and enjoy the advantages as a registered member.

(This website will be ad-free after a complete free sign up.)

New Post 20.07.2010 00:51  
Tree Structure | Board Structure
Post New Thread Post Reply
GFX-Sector » Coding Area » Scripte & Downloads » [Python3] Simple Template System

Similar topics to [Python3] Simple Template System
Thread
[Dienstleistung] Logo/Template für ein Onlineshop mit Vergütung!! (Forum: Archiv)
Game Template (Forum: Archiv für Anfragen)
Simple | fiRe.worX (Forum: Signaturen/Avatare)
[W.I.P]Blue Template (Forum: Designs)
Simples Portfolio Design(online) (Forum: Designs)