动态插入模板到基础模板
Dynamic insert the template to the base template
我想动态插入模板到基础模板:
我有三个tpl
,名字test.tpl
,test01.tpl
,test02.tpl
:
test.tpl
的代码:
<html>
<head>
<title>{$title}</title>
</head>
{if $v eq 1}
// there I want it to be test01.tpl, how to implements this?
{elseif $v eq 2}
// there I want it to be test02.tpl
{/if}
</body>
</html>
使用include函数
{include file='test01.tpl'}
https://www.smarty.net/docsv2/en/language.function.include.tpl
看看这个:
<html>
<head>
<title>{$title}</title>
</head>
<body>
{if $v eq 1}
{include file='test01.tpl'}
{elseif $v eq 2}
{include file='test02.tpl'}
{/if}
</body>
</html>
{include} 标签用于在当前模板中包含其他模板。
<html>
<head>
<title>{$title}</title>
</head>
<body>
{if $v eq 1}
{include file="test01.tpl"}
{elseif $v eq 2}
{include file="test02.tpl"}
{/if}
</body>
</html>
这个{include}标签在条件成立时包含目标文件。
我想动态插入模板到基础模板:
我有三个tpl
,名字test.tpl
,test01.tpl
,test02.tpl
:
test.tpl
的代码:
<html>
<head>
<title>{$title}</title>
</head>
{if $v eq 1}
// there I want it to be test01.tpl, how to implements this?
{elseif $v eq 2}
// there I want it to be test02.tpl
{/if}
</body>
</html>
使用include函数
{include file='test01.tpl'}
https://www.smarty.net/docsv2/en/language.function.include.tpl
看看这个:
<html>
<head>
<title>{$title}</title>
</head>
<body>
{if $v eq 1}
{include file='test01.tpl'}
{elseif $v eq 2}
{include file='test02.tpl'}
{/if}
</body>
</html>
{include} 标签用于在当前模板中包含其他模板。
<html>
<head>
<title>{$title}</title>
</head>
<body>
{if $v eq 1}
{include file="test01.tpl"}
{elseif $v eq 2}
{include file="test02.tpl"}
{/if}
</body>
</html>
这个{include}标签在条件成立时包含目标文件。