Alfdesign
(Robert Medvid)
1
Hi,
I have text for site content in database, for example:
"My site is at <? CHtml::link("text", "www.site.com"); ?>"
After parse the text I would like to have at page:
"My site is at <a href="www.site.com">text</a>"
but I have no idea how to do it.
foe_1
(foe#1)
2
Why are you storing frameworks code in the DB? If tomorrow, the CHtml changes, you tuples value needs to be changed as well.
Can you do something like this?
$dbColVal = 'My site is at '. CHtml::link(“text”, “www.site.com”);
Then store $dbColVal in the DB.
Alfdesign
(Robert Medvid)
3
Ok, you are right,
but if I can use helpers for links or images, how can I do it?
Before I have in Smarty following solution.
file content.tpl
<h1>Dear {$contact.name}</h1>,
<p>Welcome and thankyou for signing up as a member of our user group.</p>
{img src="image"}
file function.img.php
<?php
/**
* Smarty {img} function plugin
*
* Examples:
* {img id='image-id'}
*/
function smarty_function_img($params, &$smarty)
{
$src = $params['src'];
$image = getimagesize($src);
return "<img src='/images/{$src}.jpg' />";
}
?>
$smarty->fetch('content.tpl')
Output:
<h1>Dear Mike</h1>,
<p>Welcome and thankyou for signing up as a member of our user group.</p>
<img src='/images/image.jpg' />
Any solution in Yii?
olafure
(Olafure)
4
<h1>Dear <?= $contact->name ?></h1>,
<p>Welcome and thankyou for signing up as a member of our user group.</p>
<?= TPL::img('image') ?>
You would pass the $contact object to the render() function but you'd have to write your TPL class yourself:
class TPL {
static function img($src) {
return "<img src='/images/$src.jpg' />";
}
}
You could also write your own template parser if you want to keep the {} syntax.