14

can some 1 tell how to break this sort of String in smarty what i want is "1" as price and "dollar" as currency type.

"1|dollar"

please reply.

1 Answer 1

34

You could do something like this:

{assign var=someVar value="|"|explode:"1|dollar"}

and then access "1" and "dollar" through 0 and 1 indexes of the "someVar" variable like below,

{$somevar[0]} and {$somevar[1]}

6
  • thx for answer. I tried that approach when i dumped the $somevar i can only get "1" nothing more. Any idea?
    – temp-learn
    Commented Dec 2, 2011 at 12:04
  • How did you try to access the "1" and "dollar"? Commented Dec 2, 2011 at 12:07
  • 1
    {$somevar[0]} and {$somevar[1]}
    – temp-learn
    Commented Dec 2, 2011 at 12:09
  • i also tried this {print_r|$somevar} this actually displays "1"
    – temp-learn
    Commented Dec 2, 2011 at 12:09
  • 3
    Isn't smarty case sensetive? You should write {$someVar[0]}. Also try with {$someVar.0} ... sorry my smarty knowledge is a bit rusty :) Commented Dec 2, 2011 at 12:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.