(2) Templates :-
we will talk about :-
Templates Functions
In the hello.ring we have this code
In the hello.html we have this code
The Page source is :-
as you can see we have called the bootstrap and j-Query localy .
Note:- We will learn how to use templates after we know the template functions .
It can be used Like the function template()...
the difference between template() and template_exe() is the template_exe do not need an Object to execute codes ,So it need one parameter contain the html page name.
We will talk about this function after version 1.0 ...
Using Templates
Now We will learn how to use templates.
In the route.ring we have this code
In the test_template.ring we have this code
In the test_template.html we have this code
The Page source :-
In the route.ring we have this code
In the test_template.ring we have this code
In the test_template.html we have this code
The Page source :-
We will make a CRUD Application After we learn how to use Mysql with Dragon-Ring.
we will talk about :-
- Templates Functions .
- Using Templates .
- Create Template Application.
Templates Functions
Note: The templates functions read file from this path 'website/templates'
We have a different functions for templates :-
(1) Template(html_Page_name,Object)
To use this functions you have to create a controller for the html page you want to use .
In the route.ring we have this code
#!ring -cgi load 'dragon-ring.ring' import system.Web app.route('HelloWorld',:ringfile,"hello.ring")
In the hello.ring we have this code
import system.Web
dring{
html(template('hello.html',null))
}
In the hello.html we have this code
<h1>Hello World From Template .</h1>
The Page source is :-
<!DOCTYPE html><html lang="en">
<head>
<meta charset="ISO-8859-1">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<meta name="generator" content="Jekyll v4.1.1">
<link rel="stylesheet" type="text/css" href="bootstrap/bootstrap.css">
<script type="text/javascript" src="bootstrap/jq.js">$(document).ready();
</script>
</head>
<body>
<h1>Hello World From Template .</h1>
</body>
<script type="text/javascript" src="bootstrap/bootstrap.js">
</script>
</html>
as you can see we have called the bootstrap and j-Query localy .
Note:- We will learn how to use templates after we know the template functions .
(2) Template_Exe(html_Page_name)
It can be used Like the function template()...
the difference between template() and template_exe() is the template_exe do not need an Object to execute codes ,So it need one parameter contain the html page name.
import system.Web
dring{
html(template_exe('hello.html'))
}
(3) website_template(html_Page_name,Object)
We will talk about this function after version 1.0 ...
Using Templates
Now We will learn how to use templates.
{%= Ring Expression %}
{% Ring Statements %}
Create Template Application.
In the route.ring we have this code
#!ring -cgi load 'dragon-ring.ring' import system.Web app.route('test_template',:ringfile,"test_template.ring")
In the test_template.ring we have this code
import system.Web
new test_template{start()}
class test_template
name = "Mohannad"
func start
dring{
html(template('test_template.html',this))
}
In the test_template.html we have this code
<h1>Hello World From Template .</h1>
{% for x in 1:5 %}
<h1>Hello {%=name + ' ' + x %}</h1><br/>
{% next %}
The Page source :-
<h1>Hello World From Template .</h1>
<h1>Hello Mohannad 1</h1><br/>
<h1>Hello Mohannad 2</h1><br/>
<h1>Hello Mohannad 3</h1><br/>
<h1>Hello Mohannad 4</h1><br/>
<h1>Hello Mohannad 5</h1><br/>
Another example About Create Template Application.
In the route.ring we have this code
#!ring -cgi load 'dragon-ring.ring' import system.Web app.route('test_template',:ringfile,"test_template.ring")
In the test_template.ring we have this code
import system.Web
dring{
html(template_exe('test_template.html'))
}
In the test_template.html we have this code
<h1>Hello World From Template .</h1>
{% for x in 1:5 %}
<h1>Hello {%=x %}</h1><br/>
{% next %}
The Page source :-
<h1>Hello World From Template .</h1>
<h1>Hello 1</h1><br/>
<h1>Hello 2</h1><br/>
<h1>Hello 3</h1><br/>
<h1>Hello 4</h1><br/>
<h1>Hello 5</h1><br/>
We will make a CRUD Application After we learn how to use Mysql with Dragon-Ring.
I hope it was easy for you ...