26 votes
Accepted

How to add a CMS block programmatically in Magento 2?

add this to the your class: private $blockFactory; and make your constructor look like this: public function __construct( PageFactory $pageFactory, \Magento\Cms\Model\BlockFactory $...
Marius's user avatar
  • 198k
25 votes

Add a static image on PHTML page and CMS Blocks : Magento2

For your custom module create a directory structure like Company/Module/view/frontend/web/images/image-icon.png and in phtml use following code <img src='<?php echo $this->getViewFileUrl('...
Manish's user avatar
  • 3,106
23 votes

Magento2 contact form in CMS page

Call your contact form block with template file in the cms pages. Try below code : {{block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml"}}
Manthan Dave's user avatar
  • 9,816
17 votes
Accepted

Magento2 - Is it possible to get base url in a static block?

You can get base url in static block like this. <a href="{{store direct_url="business"}}">Your link</a>
Suresh Chikani's user avatar
17 votes
Accepted

Magento2 images in CMS block

Use Of {{view url=""}} You have to use view url like below for all images are coming from theme folder, app/design/frontend/{Vendor}/{themename}/web/images/ {{view url="images/natale/IMG_7300.JPG"...
Rakesh Jesadiya's user avatar
15 votes

How to add a CMS block programmatically in Magento 2?

You can try the following solution: Add 2 classes to the constructor: /** * @var \Magento\Cms\Model\BlockFactory */ protected $blockFactory; /** * @var \Magento\Cms\Model\BlockRepository */ ...
Mageworx's user avatar
  • 3,796
14 votes

Add a static image on PHTML page and CMS Blocks : Magento2

Easy solution: Put your image on Your Magento 2 Path: /app/design/frontend/< Vendor >/< theme >/web/images Use this code to call the image in phtml file: echo $block->...
Deepak Bhatta's user avatar
14 votes
Accepted

Magento 2: How to call CMS Block in email templates?

We can try: {{block class="Magento\\Cms\\Block\\Block" area='frontend' block_id="mail_include_header"}} We can see more how to add a block to email: vendor/magento/module-sales/view/frontend/email/...
Khoa TruongDinh's user avatar
12 votes
Accepted

Magento 2 - How to add or insert PDF file in a CMS page?

First, you need to add the files inside your project so magento can display them on the back office There is two ways : The simplier way : just add your file via ftp to media/wysiwyg/[...
Renaud's user avatar
  • 136
12 votes
Accepted

Magento 2: Get WYSIWYG editor's data in frontend?

Let's say the block that displays your content is called Vendor\Module\Block\Entity. Add a dependency Zend_Filter_Interface to your block like this: protected $templateProcessor; public function ...
Marius's user avatar
  • 198k
11 votes
Accepted

WYSIWYG / TinyMCE Editor keeps removing <a> tags in CMS blocks in Magento 2

This issue has actually already existed in Magento 1, it's due to the TinyMCE editor which will just strip invalid HTML from the user input, sometimes it considers a little too much to be invalid, ...
TiEul's user avatar
  • 1,297
11 votes
Accepted

store_url does not render link correctly

Add store direct_url instead of store_url <a href="{{store direct_url='produkte/insektenschutz/fenster/spannrahmen.html'}}"> spannrahmen.html will show after this.
Shoaib Munir's user avatar
  • 9,434
9 votes
Accepted

Magento 2 Load - Block (CMS Static Block in Magento 1 terms)

On __construct function,you need inject \Magento\Cms\Model\Template\FilterProvider \Magento\Store\Model\StoreManagerInterface \Magento\Cms\Model\BlockFactory for getting data. You can try below as ...
Amit Bera's user avatar
  • 77.5k
9 votes

Edit the default Magento2 cookie message

Try following: Copy file to your frontend theme and update text as you want. FROM: vendor/magento/module-cookie/view/frontend/templates/html/notices.phtml TO: app/design/frontend/[VendorName]/[...
Pratik Oza's user avatar
  • 3,972
8 votes

store_url does not render link correctly

Try adding this to your block: <a href="{{store direct_url="produkte/insektenschutz/fenster/spannrahmen.html"}}">Link to Base URL</a>
HIren Kadivar's user avatar
7 votes
Accepted

Magento 2.3.5 - Inline Translate within a CMS Block

php translate will not work in static block you need to add like: <h1 class="hero-h1">{{trans "Welcome to this website" }}</h1> You can add translation as per link
Pawan's user avatar
  • 5,856
6 votes

Magento 2 : Adding static blocks to specific section of pages with custom module layout xml file

If you want to call static-block in 2columns-left page, you can simply do it using, here below you can change quickblock with your static-block identifier. <referenceContainer name="sidebar.main"&...
Rakesh Jesadiya's user avatar
6 votes
Accepted

Magento 1.9 - Store Hours of Operation not available for CMS

You need to go to System -> Permissions -> Variables and add new variable general/store_information/hours as allowed for it to work on frontend. As to why it is like this, I guess they just forgot ...
Anton's user avatar
  • 86
6 votes
Accepted

magento 2 : how to use phtml in cms static block

You can use Magento\Framework\View\Element\Template basic template. Try this: <div id="something"> {{block class="Magento\Framework\View\Element\Template" name="test" template="path/to/my/...
Phoenix128_RiccardoT's user avatar
6 votes
Accepted

get cms block title magento2

Out of the box you cannot retrieve the block title. What you'll have to do is: First, create your own block class that extends Magento\Cms\Block\Block Optional: if you want the getTitle method to ...
Raphael at Digital Pianism's user avatar
6 votes

Get content of CMS block by identifier

I got it! The problem was the getById() method it DOES take a identifier as well as the id, my problem was that my test block had the identifier "123" and although it is a string either magento or php ...
TrytoFly's user avatar
  • 634
5 votes
Accepted

Adding a block to CMS page is not working

Allow block in dailydeal/list in admin-> system-> permission->blocks->add new block -> Enter dailydeal/list in Block name and Yes in Is Allowed it should resolve your issue.
Aman Alam's user avatar
  • 1,318
5 votes

Magento2 contact form in CMS page

{{block class="Magento\Contact\Block\ContactForm" name="contactForm" template="Magento_Contact::form.phtml"}}
omelandr's user avatar
  • 1,267
5 votes
Accepted

Saving cms blocks after 2.3.1 upgrade now display the html on frontend

The Page Builder addition does some extra processing on blocks, which happens during the _toHtml() method of a Magento\Cms\Block\Block class, triggered by a FilterProvider. My fix was to inject a ...
jay's user avatar
  • 443
5 votes

How to remove extra divs in my Page Builder CMS blocks?

In page builder when creating CMS block add class=> ignore-div then add style for it .ignore-div {display: contents;} It will ignore wrapper
BeardMan's user avatar
4 votes
Accepted

Magento 2 How to Add CMS Block to Email Confirmation Email

Should create new custom theme And then, copy the default email template to your custom theme: app/design/frontend/Vendor/Theme/Magento_Sales/email/order_new.html Add cms block to email template {{...
Khoa TruongDinh's user avatar
4 votes
Accepted

How to call CMS Block via its identifier in Product edit / add page?

You could create a template with below code: <?php $_product = $block->getProduct(); $shippingtype = $_product->getResource()->getAttribute('shippingtype')->getFrontend()->getValue($...
harri's user avatar
  • 5,465
4 votes
Accepted

Add CMS Block to Sidebar in whole magento 2 site

Your XML file code should be: <referenceContainer name="sidebar.additional"> <block class="Magento\Cms\Block\Block" name="yourblockid"> <arguments> <...
Abhishek Panchal's user avatar
4 votes

what is the difference between cms page link and cms static block. Catalog product link and catalog category link

CMS page: A page which is dynamic and editable (not the category page and product page) such as informative pages. (Content > Pages) CMS block: It includes any dynamic content of your page, which can ...
Ruhani's user avatar
  • 572
4 votes

Why my homepage doesn't display a cms block content?

To call static block in cms page {{block id="this_is_a_block_identifier"}} Reference
Addify's user avatar
  • 769

Only top scored, non community-wiki answers of a minimum length are eligible