Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Smarty Variable In Smarty Variable Rate Topic   - - - - -

 
  • larrezz91
  • Advanced Member
  • Trial users
  • Join Date: 23-Oct 14
  • 50 posts

Posted 27 May 2016 - 09:27 AM #1

Hi,

 

I have a question, I have a created a Smarty Block in CS Cart, which contains a Smarty variable {$test}. The content of this variable is something like

 

"This is an test, where I show a variable test_content: {$test_content}."

 

The problem is that {$test_content} is displayed literally. I have tried using something like

 

{$test|replace:"{$test_content}":$test_content} but the string is not being replaced. Probably because {$test_content} is seen as a variable in the replace statement.

 

Anyone out there who know how to solve this problem?

 

Thanks in advance!

 

Allan

 

 



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19036 posts

Posted 27 May 2016 - 01:09 PM #2

Use another placeholder in the value of the variable. E.g.

Some text [CONTENT] lorem ipsum

Then use 

{$test|replace:"[CONTENT]":$test_content}

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11248 posts

Posted 27 May 2016 - 05:10 PM #3

Another alternative when your string is literal string like your example:

{assign var="test" value="This is an test, where I show a variable test_content: `$test_content`."}

Then use as:

<p>Here is the result: {$test}</p>

The approach Ecom has used works best when your string is actually a language variable (better practice) rather than a literal string.  I.e. the code could then look like (I prefer str_replace rather than the built in smarty replace - there are always different ways):

{"[CONTENT]"|str_replace:$test_content:__("my_lang_variable")}

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • straygecko
  • Advanced Member
  • Members
  • Join Date: 01-May 13
  • 93 posts

Posted 27 May 2016 - 05:39 PM #4

{eval var=$test}



 

Posted 31 May 2016 - 06:53 AM #5

hi all,

 

I tried to do above mentioned problem so I have implemented in following, you can use if you think it is correct.

 

For this set language in language translation.

Language variable : content

value: [content]

{assign var=test value="NEW TEXT"}

{assign var=demo value="Hello how are you {__("content", ["[content]" => $test ] )}"}
{$demo}

The output will be

 

"Hello how are you NEW TEXT"

 

In this I have used both smarty and cs-cart language feature.

But this will work only when working in cs-cart.

 

-Himanshu Dangwal



 
  • larrezz91
  • Advanced Member
  • Trial users
  • Join Date: 23-Oct 14
  • 50 posts

Posted 15 July 2016 - 01:54 PM #6

Thanks all for replying, i've made use of EcomLabs' solution.



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19036 posts

Posted 15 July 2016 - 02:01 PM #7

You are welcome!


GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.