Jump to content

[SOLVED] pass a variable from product.js to product.tpl


nandelbosc

Recommended Posts

Hi!

 

I have some variables declared on /themes/default/js/product.js file.

 

For example...

var test_1 = 'text for test 1';
var test_2 = 'text for test 2';
var test_3 = 'text for test 3';

I want to use them in /themes/default/product.tpl. How can I do that?

 

I tried several ways, but withous success... :(

 

Thank's in advance!

Edited by nandelbosc (see edit history)
Link to comment
Share on other sites

Mention not :)

 

So fot that you have to pass a variable to that HTML tag using javascript.

 

for example.,

 

if you want to pass variable

    var text_1 to input tag which has name with text_1

 

this is product.tpl sample HTML tag format from which you will get your varible value

      <input type="text" name="text_1" id="text_1" value="" />

 

you just type this line in your product.js

      $("#text_1").val(text_1); // Format --> $("#<HTML tag id>").val(<name of your js variable>)

 

I hope this will help you better to understand

:)

 

Regards

Kartik

Link to comment
Share on other sites

Mention not :)

 

So fot that you have to pass a variable to that HTML tag using javascript.

 

for example.,

 

if you want to pass variable

    var text_1 to input tag which has name with text_1

 

this is product.tpl sample HTML tag format from which you will get your varible value

      <input type="text" name="text_1" id="text_1" value="" />

 

you just type this line in your product.js

      $("#text_1").val(text_1); // Format --> $("#<HTML tag id>").val(<name of your js variable>)

 

I hope this will help you better to understand

:)

 

Regards

Kartik

 

Ok, I have it working using span tag...

<span id="text_1">

But I want to use with the if statement and i don't know how without a tipical variable  :unsure:

 

For example, if it were possible to have the value in a variable standard I use if like this...

{if $text_1 == 'text ok'}
<b>$text_1</b>
{else}
<i>$text_1</i>
{/if}

But without a variable I don't know how to do the previous if...  :rolleyes:

 

Thank's again for your quick quick reply!

Link to comment
Share on other sites

Ok, I have it working using span tag...

<span id="text_1">

But I want to use with the if statement and i don't know how without a tipical variable  :unsure:

 

For example, if it were possible to have the value in a variable standard I use if like this...

{if $text_1 == 'text ok'}
<b>$text_1</b>
{else}
<i>$text_1</i>
{/if}

But without a variable I don't know how to do the previous if...  :rolleyes:

 

Thank's again for your quick quick reply!

Ok,

 

for that you just apply your if condition in js file

var taxt_1="text ok";

your tpl format should be

<b class="class_b" id="class_b"></b>
<i class="class_i" id="class_i"></i>

js if condition is like

if(text_1 == "text ok")
{ $("#class_b").val(text_1); $(".class_b").show(); $(".class_i").hide();  }
else
{ $("#class_i").val(text_1); $(".class_i").show(); $(".class_b").hide(); }

So you will get filtered output. :)

 

Regards

Kartik

Link to comment
Share on other sites

Ok,

 

for that you just apply your if condition in js file

var taxt_1="text ok";

your tpl format should be

<b class="class_b" id="class_b"></b>
<i class="class_i" id="class_i"></i>

js if condition is like

if(text_1 == "text ok")
{ $("#class_b").val(text_1); $(".class_b").show(); $(".class_i").hide();  }
else
{ $("#class_i").val(text_1); $(".class_i").show(); $(".class_b").hide(); }

So you will get filtered output. :)

 

Regards

Kartik

 

I would prefer to do it through the variables, as I said at the beginning, but now I think I'll be able to live with your solution...  :D

 

Thank you very much Kartik!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...