Fraenkiman e544ed6d9a Smatry Release 4.4.1 on Feb-2024
Comparing changes: https://github.com/smarty-php/smarty/compare/v4.3.1...v4.4.1

It is noticeable that Smarty 4.3.1 does not officially support PHP 8.3. Is only supported with 4.4.0.

Remark:

During tests with Smarty 4.5.1, it was noticed that the following warning occurs:
Deprecated: Using the unregistered function "function_exists" in a template is deprecated and will be removed in a future version. Use Smarty::registerPlugin to explicitly register a custom modifier.

As of Smarty 5.X.X, templates must be revised again.
The Smarty release 5.0.2 is already officially available. However, integration into FlatPress is not entirely trivial.
2024-04-14 18:37:39 +02:00

1.1 KiB

templateExists()

checks whether the specified template exists

Description

bool

templateExists

string

template

It can accept either a path to the template on the filesystem or a resource string specifying the template.

This example uses $_GET['page'] to {include} a content template. If the template does not exist then an error page is displayed instead. First the page_container.tpl

<html>
<head><title>{$title}</title></head>
<body>
{include file='page_top.tpl'}

{* include middle content page *}
{include file=$content_template}

{include file='page_footer.tpl'}
</body>

And the php script

<?php

// set the filename eg index.inc.tpl
$mid_template = $_GET['page'].'.inc.tpl';

if( !$smarty->templateExists($mid_template) ){
    $mid_template = 'page_not_found.tpl';
}
$smarty->assign('content_template', $mid_template);

$smarty->display('page_container.tpl');

?>

See also display(), fetch(), {include} and {insert}