Page 1 of 1

smarty (help)

Posted: Tue Mar 13, 2007 12:34 pm
by spamyboy

Code: Select all

$sSQL = "SELECT aID,aTitle,aShortDesc,aDate,aHits FROM ".PREFIX."tutorials WHERE aDisplay='Y' ORDER BY aDate DESC LIMIT 5";
$result = $db->query($sSQL);
while (
$row = $result->fetchRow())
{
	$data2[]=$row;
}

$template->assign('data2',$data2);

Code: Select all

<div id="rightColumn">
<div class="rbox">
<div class="rboxtitle">Leatest tutorials </div>
<!--{foreach from=$data2 item="entry"}-->
<div class="rboxother">
<div class="rboxothertitle"><a href="index.php?cmd=tutorial&id={$entry.aID}">{$entry.aTitle}</a></div>
<div class="rboxotherdesc">{$entry.aShortDesc}</div>
</div>
<!--{/foreach}--></div>
So now what I'm trying to do... I can't find find to substr aShortDesc variable.

Here is how do I imagine it:

Code: Select all

$aShortDesc=substr($aShortDesc, 1);
$aShortDesc."...";
But where should I do it ? :|
pleas give example.

Posted: Tue Mar 13, 2007 12:46 pm
by veridicus
The closest thing I know of within smarty is the truncate function

Code: Select all

<div class="rboxotherdesc">{$entry.aShortDesc|truncate:1:""}</div>
That will return the first character of aShortDesc.

Posted: Tue Mar 13, 2007 12:52 pm
by spamyboy
Could you give me example in this part of code ? Couse I want to do more things with that description over PHP.

Code: Select all

$sSQL = "SELECT aID,aTitle,aShortDesc,aDate,aHits FROM ".PREFIX."tutorials WHERE aDisplay='Y' ORDER BY aDate DESC LIMIT 5";
$result = $db->query($sSQL);
while (
$row = $result->fetchRow())
{
        $data2[]=$row;
}

$template->assign('data2',$data2);

Posted: Tue Mar 13, 2007 1:00 pm
by veridicus
You can alter the data as you get it...

Code: Select all

$sSQL = "SELECT aID,aTitle,aShortDesc,aDate,aHits FROM ".PREFIX."tutorials WHERE aDisplay='Y' ORDER BY aDate DESC LIMIT 5";
$result = $db->query($sSQL);
while (
$row = $result->fetchRow())
{
        $row['aShortDesc'] = substr($row['aShortDesc'], 1);
        $data2[]=$row;
}

$template->assign('data2',$data2);

Posted: Tue Mar 13, 2007 1:05 pm
by spamyboy
Thanks you so mutch.