VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: suraty on November 01, 2021, 19:43:41 PM

Title: Define new div in .php file and a variable in it
Post by: suraty on November 01, 2021, 19:43:41 PM
Hello,
I am a beginner.

I want to define a div tag in the defaul.php file of productdetails page with a variable in it. Then it makes it possible to set the value of the variable.
Something like this:

<div>
<p>  the variable </p>
</div>


Is it possible to define such HTML codes?
How can I define and set that variable value?

Please help me step by step. Thanks.

Joomla version = 3
Virtuemart version =3
Title: Re: Define new div in .php file and a variable in it
Post by: AH on November 02, 2021, 10:45:56 AM
Yes that is how most of the php works for display.

What we need to know is what this new variable is meant to contain - you declare and set the value of the variable and then display it.

$mynewvariable = need to know what you want this variable to be;

<div>
<p>
<?php
  echo $mynewvariable;
?>
</p>
</div>

Title: Re: Define new div in .php file and a variable in it
Post by: suraty on November 02, 2021, 11:21:37 AM
Thank you very much for your help.

You mentioned in codes:
$mynewvariable = need to know what you want this variable to be;

Can you describe more with an example?

If I want to change this variable for any product apart, how should I define and set the variable value for every product?

Thank you
Title: Re: Define new div in .php file and a variable in it
Post by: Jörgen on November 02, 2021, 11:29:03 AM
Take another approach, make a custom field.

Jörgen
Title: Re: Define new div in .php file and a variable in it
Post by: AH on November 02, 2021, 13:50:28 PM
You need to tell us what you expect to be in this variable
Title: Re: Define new div in .php file and a variable in it
Post by: Studio 42 on November 02, 2021, 17:42:59 PM
If the "variable" is same for all products, and only need to be changed by language you can use.
<div><?php echo jtext::_('product_explain'); ?></div>

IN Joomla language overides, you define a new KEY
product_explain
and add your content so you can change this value any time after.
If you need to set this by product then you need to create a new product custom field
Then you add this code at the position you want display this field
<?php echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'explain')); ?>
In your product customfield you fill the field "position" : "explain"
Title: Re: Define new div in .php file and a variable in it
Post by: suraty on November 03, 2021, 06:52:03 AM
Thank you very much.
Your answers solved my confusing problem, especially Studio 42 answer!
Thanks so much for your helps.
Best wishes to you.
Good luck!
Title: Re: Define new div in .php file and a variable in it
Post by: suraty on November 03, 2021, 16:03:05 PM
Dear members,
My problem is solved again with your help.
I am really thankful to you.
Mark this question as solved.
God bless you!