News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Define new div in .php file and a variable in it

Started by suraty, November 01, 2021, 19:43:41 PM

Previous topic - Next topic

suraty

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

AH

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>

Regards
A

Joomla 4.4.5
php 8.1

suraty

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

Jörgen

Take another approach, make a custom field.

Jörgen
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

AH

You need to tell us what you expect to be in this variable
Regards
A

Joomla 4.4.5
php 8.1

Studio 42

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"

suraty

#6
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!

suraty

Dear members,
My problem is solved again with your help.
I am really thankful to you.
Mark this question as solved.
God bless you!