Parse PHP to JS (Javascript)?

Hi All,



I’m implementing “Power Reviews” which replaces CS-Cart’s typical Review block.

I’ve implemented just about everything else except actually getting it to work :mrgreen:



Here’s what I would like to do:

Input a smarty variable into JavaScript.



Replace “[COLOR=Red]PRODUCT_CODE[/COLOR]”

```php




```with

```php
{$pr_productcode}
```I have generated "$pr_productcode" from "$product.product_code" (Smarty Variable)
In order to accomplish this I've added this code to index.tpl (/skins//customer/index.tpl)

```php
{assign var=pr_productcode value=$product.product_code}
{php}

// CREATE PRCODE from $PRODUCT CODE
$prcode = $this->get_template_vars('pr_productcode');// GRAB PRODUCT CODE FOR POWERREVIEW
{/php}
```

Jesse “The CS-Cart Whisperer” :smiley:

To use the smarty code in the js, try something like this:



To put the smarty value into a php variable:

```php

$pr_pc = $this->get_template_vars('pr_productcode');
?>

```



Put the php into your javascript:

```php




```

[quote name=‘adodric’]To use the smarty code in the js, try something like this:



To put the smarty value into a php variable:

```php

$pr_pc = $this->get_template_vars('pr_productcode');
?>

```Put the php into your javascript:

```php




```[/quote]

Doesn't appear to parse the actual code.

I can parse PHP using the following code and get a response, just won't allow it to happen using the javascript..
```php
{php} echo LOL; {/php}
```

Proberly better to display it via code portions.



index.tpl

/skins/basic/customer/index.tpl


```php

{* $Id: index.tpl 7454 2009-05-14 08:42:13Z angel $ *}




{strip}

{if $page_title}
{$page_title}
{else}
{foreach from=$breadcrumbs item=i name="bkt"}
{if !$smarty.foreach.bkt.first}{$i.title}{if !$smarty.foreach.bkt.last} :: {/if}{/if}
{/foreach}
{if !$skip_page_title}{if $breadcrumbs|count > 1} - {/if}{$lang.page_title_text}{/if}
{/if}

{/strip}
{include file="meta.tpl"}

{include file="common_templates/styles.tpl" include_dropdown=true}
{include file="common_templates/scripts.tpl"}





{assign var=pr_productcode value=$product.product_code}

{php}

// CREATE PRCODE from $PRODUCT CODE
$pr_productcode = $this->get_template_vars('pr_productcode');
{/php}

{if "SKINS_PANEL"|defined}
{include file="demo_skin_selector.tpl"}
{/if}


{include file="common_templates/loading_box.tpl"}
{include file="common_templates/notification.tpl"}

{include file="main.tpl"}

{if "TRANSLATION_MODE"|defined}
{include file="common_templates/translate_box.tpl"}
{/if}
{if "CUSTOMIZATION_MODE"|defined}
{include file="common_templates/template_editor.tpl"}
{/if}
{if "CUSTOMIZATION_MODE"|defined || "TRANSLATION_MODE"|defined}
{include file="common_templates/design_mode_panel.tpl"}
{/if}


{hook name="index:footer"}
{/hook}

{literal}

{/literal}




```

Ok, sorry. In my haste I didn’t read the bottom part of your original post.



Maybe try something like:


```php



{assign var=pr_productcode value=$product.product_code}

{php}



// CREATE PRCODE from $PRODUCT CODE

$prcode = $this->get_template_vars(‘pr_productcode’);// GRAB PRODUCT CODE FOR POWERREVIEW

{/php}



…OTHER CODE BETWEEN…



{literal}{/literal}

```

[quote name=‘adodric’]Ok, sorry. In my haste I didn’t read the bottom part of your original post.



Is this part of your code in the tpl file? If so I assume the js is between {literal} tags?:

```php



```Maybe try something like:

```php

{literal}{/literal}
```[/quote]

Great Minds think alike!

I tried your second method without reading you post, coming back to paste the same thing!!! Thank you for your help, definetly put me on the right track

OR a simpler way if that works is to just eliminate the php part and put the smarty into the js:


```php

{literal}{/literal}


```

[quote name=‘adodric’]Ok, sorry. In my haste I didn’t read the bottom part of your original post.



Maybe try something like:


```php



{assign var=pr_productcode value=$product.product_code}

{php}



// CREATE PRCODE from $PRODUCT CODE

$prcode = $this->get_template_vars(‘pr_productcode’);// GRAB PRODUCT CODE FOR POWERREVIEW

{/php}



…OTHER CODE BETWEEN…



{literal}{/literal}

```[/quote]

[quote name='adodric']OR a simpler way if that works is to just eliminate the php part and put the smarty into the js:

```php
{literal}{/literal}

```[/quote]

I tried that however it does not seem to work since the code is encased in a TPL (requires {php} for PHP code blocks.)

I thought that $pr_productcode was the smarty variable and not the php variable. That’s what I meant in the last post of mine.