0

Unfortunately, in my current workplace, I have to use Smarty on a project they had before i was employed.

Anyway, I am trying to call in a Dynamic html title for each category in the app.

So for example, the title used to be pageTitle="{$category} in {$areaname}".

However I now want it to be: pageTitle="{html_title}". Within html_title (from db), is a string, for example: "Monkeys in the {areaname}" Where {areaname} could be "jungle".

When I output the result, I get:

"Monkeys in {areaname}".

So to cut a long story short, its not recognizing the variable. It is treating it as a string. I have googled my head off and can't find an answer. I hate smarty!
Please help!

Shreyos Adikari
  • 12,348
  • 19
  • 73
  • 82
  • Monkeys in the {$areaname} will not work? – Tahir Yasin Nov 21 '12 at 10:23
  • I can't work out why? In Smarty can you not have a variable within a variable? – user1574256 Nov 21 '12 at 10:25
  • How do you set "{html_title}" ? In this (wrong) way ? `$smarty->assign("html_title","Monkeys in {areaname}")` ? – alesdario Nov 21 '12 at 10:34
  • It is set using a plugin: {getServiceCategoryTitle categoryID=$id assign="html_title"} – user1574256 Nov 21 '12 at 10:44
  • And the value from the database is "Monkey in the {$areaName}". {$areaName} is already assigned elsewhere on the page. But instead of displaying the value of {$areaName} it is actually displaying {$areaName} – user1574256 Nov 21 '12 at 10:46
  • "Monkey in the {$areaName}" is only a string and Smarty works right. It doesn't process the output of functions or plugins. I suppose that you should process this string during "getServiceCategoryTitle" execution, before return the value. – alesdario Nov 21 '12 at 11:37

1 Answers1

1

Couldn't you just do something like

$html_title = preg_replace("/{areaname}/", "jungle", $html_title);

after fetching the title from the database?

August Karlstrom
  • 10,773
  • 7
  • 38
  • 60