I'm new to Magento
I want to create a block in the admin panel (Content > Elements > Blocks) which contains HTML code, CSS style, and some dynamic parameters under its content box.
Example: <div> {{$data}} </div>
How can I do it? How I can define the $data in PHTML or layout?
Do any official documents relate to this?
-
Can you please share the detail of the data that you want to fetch in $data?IntraPersonalLearner– IntraPersonalLearner2021年11月08日 06:06:10 +00:00Commented Nov 8, 2021 at 6:06
-
Do you want to fetch values of any product/category/custom attribute?IntraPersonalLearner– IntraPersonalLearner2021年11月08日 06:16:16 +00:00Commented Nov 8, 2021 at 6:16
2 Answers 2
Usually what you would do is define a template in your block.
Create a block with this content in admin
{{block class="Cpy\ModuleName\Block\BlockName" name="block-test" template="Your_Theme::html/your-path/your-file.phtml"}}
Then you can define any variable you want in the BlockName block and use them in the your-file.phtml
Phtml will have an instance of Block class.
So in phtml file you can have that dynamic variable and pass it to one of the block functions.
The other way of passing a predefined argument value can be by XML but you have stated a dynamic parameter. Other option could be to use http Request object or some registry variable.