Im really new to smart. I would like to know how to use the PHP feature set in smarty. I understand that some functions can be used immediately.
Example: {$my_string|strip_tags}
Im using PDO along with smarty. Please see below code where I receive messages
$stmnt = $conn->prepare("SELECT post_id, post_title FROM posts ORDER BY post_id DESC");
$stmnt ->execute();
$row = $stmnt ->fetchAll();
$my_template = new Smarty;
$my_template->debugging = false;
$my_template->caching = true;
$my_template->cache_lifetime = 120;
$my_template->setTemplateDir('./templates/’');
$my_template->assign("row", $row);
$my_template->display('posts.tpl');
{foreach $row as $r}
{/foreach}
I want to use some php functions to create url from post_title. So usually what i do in php
<?php
foreach($row as $r){
$post_title = $r[‘post_title’];
$create_link = preg_replace("![^a-z0-9]+!i", "-", $post_title);
$create_link = urlencode($create_link);
$create_link = strtolower($create_link);
?>
<a href="posts/<?php echo $create_link;?>"><?php echo $post_title ;?></a>
<?php } ?>
How to achieve the same result with smarty? I searched everywhere, but could not find the answers. Appreciate your time.
source
share