0

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?

2
  • Can you please share the detail of the data that you want to fetch in $data? Commented Nov 8, 2021 at 6:06
  • Do you want to fetch values of any product/category/custom attribute? Commented Nov 8, 2021 at 6:16

2 Answers 2

0

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

answered Nov 8, 2021 at 9:34
0

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.

answered Nov 8, 2021 at 18:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.