| 148 |
lars |
1 |
templateExists()
|
|
|
2 |
|
|
|
3 |
checks whether the specified template exists
|
|
|
4 |
|
|
|
5 |
Description
|
|
|
6 |
===========
|
|
|
7 |
|
|
|
8 |
bool
|
|
|
9 |
|
|
|
10 |
templateExists
|
|
|
11 |
|
|
|
12 |
string
|
|
|
13 |
|
|
|
14 |
template
|
|
|
15 |
|
|
|
16 |
It can accept either a path to the template on the filesystem or a
|
|
|
17 |
resource string specifying the template.
|
|
|
18 |
|
|
|
19 |
This example uses `$_GET['page']` to
|
|
|
20 |
[`{include}`](#language.function.include) a content template. If the
|
|
|
21 |
template does not exist then an error page is displayed instead. First
|
|
|
22 |
the `page_container.tpl`
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
<html>
|
|
|
26 |
<head><title>{$title}</title></head>
|
|
|
27 |
<body>
|
|
|
28 |
{include file='page_top.tpl'}
|
|
|
29 |
|
|
|
30 |
{* include middle content page *}
|
|
|
31 |
{include file=$content_template}
|
|
|
32 |
|
|
|
33 |
{include file='page_footer.tpl'}
|
|
|
34 |
</body>
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
And the php script
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
<?php
|
|
|
42 |
|
|
|
43 |
// set the filename eg index.inc.tpl
|
|
|
44 |
$mid_template = $_GET['page'].'.inc.tpl';
|
|
|
45 |
|
|
|
46 |
if( !$smarty->templateExists($mid_template) ){
|
|
|
47 |
$mid_template = 'page_not_found.tpl';
|
|
|
48 |
}
|
|
|
49 |
$smarty->assign('content_template', $mid_template);
|
|
|
50 |
|
|
|
51 |
$smarty->display('page_container.tpl');
|
|
|
52 |
|
|
|
53 |
?>
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
See also [`display()`](#api.display), [`fetch()`](#api.fetch),
|
|
|
58 |
[`{include}`](#language.function.include) and
|
|
|
59 |
[`{insert}`](#language.function.insert)
|