ThinkPHP 3.1.2 模板中的基本语法<1>

#
# ThinkPHP 3.1.2 模板中的基本语法

一.传统的方式,导入CSS和JS文件       
	1、css link
	   js  scr
		<link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/test.css'/>
		<script src='__PUBLIC__/Js/test.js'></script>

	2.import
		<import type='js' file='Js.test' /> //导入Public文件夹下面的Js目录中的test.js文件,import标签可以省

略type属性,默认就是js的
		<import type='css' file='Css.test' />
		//可以更改默认文件夹 设置basepath属性
		<import type='js' file='Js.my' basepath='./Other'/>

	3.load
		//方法可以自动检测导入的文件类型
		<load href='__PUBLIC__/Js/test.js' />
二、分支结构
	1、if	
		<if condition='$sex eq "男"'>
			男人是泥巴做的
			<else />
			女人是水做的
		</if>

		<if condition='$age lt 18'>
			未成年
			<elseif  condition='$age eq 18'/>
			青春年少
			<else />
			成年
		</if>
		>  gt
		<  lt
		== eq
		<= elt
		>= egt
		!= neq
		=== heq
		!== nheq

		<switch name='number'>
			<case value='1'>一个和尚挑水吃</case>
			<case value='2'>两个和尚台水吃</case>
			<case value='3'>三个和尚没水吃</case>
			<default/> 这里是默认值
		</switch>
三、循环结构
四、特殊标签
五、其他标签使用	


//引入Css文件:


<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/test.css'/>
  <title>Document</title>
 </head>
 <body>
{$name}</br>

{$Think.get.name}</br>

{$name|date='Y m d H:i:s',###}
</br>
xxxxxxxxxxx
<p>{++$name }</p>
{$Think.session.aa}</br>

 </body>
</html>




<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <link rel='stylesheet' type='text/css' href='/thinkphp2/Public/Css/test.css'/>
  <title>Document</title>
 </head>
 <body>
10</br>

</br>

1970 01 01 08:00:10</br>
xxxxxxxxxxx
<p>11</p>
</br>

 </body>
</html>


//引入Js文件:
<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/test.css'/>
  <script src='__PUBLIC__/Js/test.js'></script>
  <title>Document</title>
 </head>
 <body>
{$name}</br>

{$Think.get.name}</br>

{$name|date='Y m d H:i:s',###}
</br>
xxxxxxxxxxx
<p>{++$name }</p>
{$Think.session.aa}</br>

 </body>
</html>


//import 导入js:

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <!--<link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/test.css'/>-->
    <!--<script src='__PUBLIC__/Js/test.js'></script>-->

//默认寻找/thinkphp2/Public
<import type='js' File='Js.test'/>
  <title>Document</title>
 </head>
 <body>
{$name}</br>

{$Think.get.name}</br>

{$name|date='Y m d H:i:s',###}
</br>
xxxxxxxxxxx
<p>{++$name }</p>
{$Think.session.aa}</br>

 </body>
</html>



解析为 <script type="text/javascript" src="/thinkphp2/Public/Js/test.js"></script>

//导入Css

<import type='css' File='Css.test'/>

<import type='js' File='Js.test'/>

<link rel="stylesheet" type="text/css" href="/thinkphp2/Public/Css/test.css" />


// html 分支语句

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <!--<link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/test.css'/>-->
    <!--<script src='__PUBLIC__/Js/test.js'></script>-->
<!--<import type='css' File='Css.test'/>

<import type='js' File='Js.test'/>-->
  <title>Document</title>
 </head>
 <body>
{$sex}</br>
<if condition='$sex eq "男"'>
  男人是泥巴
  <else />
  "女人是水做的"
</if>


 </body>
</html>

//html 分支语句2 if elseif else

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <!--<link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/test.css'/>-->
    <!--<script src='__PUBLIC__/Js/test.js'></script>-->
<!--<import type='css' File='Css.test'/>

<import type='js' File='Js.test'/>-->
  <title>Document</title>
 </head>
 <body>
{$sex}</br>
<if condition='$age lt 18'>
  未成年
  <elseif  condition='$age eq 18'/>
  "青春年少"
  <else/>
  "已成年"
</if>


 </body>
</html>




//html switch case

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <!--<link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/test.css'/>-->
    <!--<script src='__PUBLIC__/Js/test.js'></script>-->
<!--<import type='css' File='Css.test'/>

<import type='js' File='Js.test'/>-->
  <title>Document</title>
 </head>
 <body>
{$sex}</br>

<switch name='number'>

<case value='1'>一个数字</case>

<case value='2'>2个数字</case>
<case value='3'>3个数字</case>

<default/> 默认值name
</switch>


 </body>
</html>



你可能感兴趣的:(ThinkPHP 3.1.2 模板中的基本语法<1>)