102

This tag is used by static tests. Any potentially unsafe output must be marked with either @escapeNotVerified or @noEscape to pass tests, the latter means that this particular usage has been checked and is safe. In the future releases all occurrences of @escapeNotVerified will be verified and either marked with @noEscape or escaped with one of these ...


75

Try like this. For ex your block class is <?php namespace Company\Helloworld\Block; use Magento\Framework\View\Element\Template; class Main extends Template { public function getMyCustomMethod() { return '<b>I Am From MyCustomMethod</b>'; } } then in any phtml file you can use following code to get method of this block....


56

You can only see some settings in developer mode. So first of all check that you are in developer mode, if not then run this command php bin/magento deploy:mode:set developer in root directory. Then go to admin panel: For Front End: Store > Configuration > Advanced > Developer > Debug > Enabled Template Path Hints for Storefront > Yes For Admin : ...


52

You can create a function for getting configuration values in your custom module's helper. <?php namespace Vendor\Module\Helper; class Data extends \Magento\Framework\App\Helper\AbstractHelper { public function getConfig($config_path) { return $this->scopeConfig->getValue( $config_path, \Magento\Store\Model\...


49

TL:DR Do you build using the native luma or blank theme ? Or anything else ? This is up to you, declaring a parent theme is optional. If you don't declare a parent you will still fallback to the modules (e.g Magento_Catalog) which provide XML and template files but no styling. Do you use any extension to help you develop your theme ? As I prefer working ...


49

Working solution. Just create or edit requirejs-config.js file from below path. /app/code/Namespace/Module/view/frontend/requirejs-config.js And place below code in requirejs-config.js var config = { map: { '*': { 'Magento_Payment/template/payment/cc-form.html': 'Namespace_Module/template/payment/cc-form.html' ...


49

The escaping methods in AbstractBlock all delegate calls to Magento\Framework\Escaper, so you'll find an overview there. Let's look at the public methods and their documentation: escapeHtml() /** * Escape string for HTML context. allowedTags will not be escaped, except the following: script, img, embed, * iframe, video, source, object, audio * * @...


40

Symlinks aren't necessarily bad. First of all: If trying to open a symlink target, the file permissions of the target are in effect. If you're not allowed to read/write/execute the symlink target, nothing happens. But: You might be able to run files outside your document root (sometimes that's actually what you want to do with them, right?). The problem ...


38

You can declare a new primary theme for your admin area by customizing config (e.g. app/etc/local.xml) with the following: <config> <stores> <admin> <design> <theme> <default>your_theme</default> </theme> </design> ...


37

You can get media url in your template file using below way but without using objectmanager you must have to define Block file with __construct() method with define storeManagerInterface in construct method. In your phtml Block file create __construct function. public $_storeManager; public function __construct(\Magento\Store\Model\StoreManagerInterface $...


36

If your block extends Magento\Catalog\Block\Product\AbstractProduct, you can use: $imageType = 'category_page_list'; // choose which image $image = $block->getImage($product, $imageType); Then either get the image URL with $image->getImageUrl(); or if you want to output it as <img> element: echo $image->toHtml(); If your block does not / ...


34

There are several helper method depending on the context. All are defined in Mage_Core_Helper_Abstract but also in Mage_Core_Block_Abstract, so you can use them with $this->...() in every template: escapeHtml(): It actually leverages htmlspecialchars with the recommended parameters to escape HTML: $result = htmlspecialchars($result, ENT_COMPAT, 'UTF-8', ...


34

In a template file, $block and $this->_currentBlock are the same thing. Take a look at the render method in the Php.php template engine. Before including the template file, this happens: $this->_currentBlock = $block; then the template file is included using a simple include $fileName;. This means that inside a template you are still inside the Php ...


29

In some instances, Magento has multiple modules trying to translate the same item. Take Add to Cart for example. In Magento the modules Mage_Catalog, Mage_Checkout, Mage_Reports, Mage_Sales, Mage_Tag, Mage_Wishlist and Mage_XmlConnect all try to translate this string. What helps in those cases is to specify which translation of which module you are trying ...


29

Create file with name app/design/frontend/[VendorName]/[theme]/Magento_Tax/templates/pricing/adjustment.phtml. base folder it's default fallbacks for all arias and used to share resources across of areas


29

Magento 2.1 The block mentioned below is now Magento\Checkout\Block\Onepage\Success Magento 2.0 The only thing you can retrieve natively on this page is the order id using the getRealOrderId() method defined in Magento\Checkout\Block\Success Thus, to get the order id you can call the following in your template: $block->getRealOrderId(); However, I ...


28

getBlockHtml('block_name_here') get's you the html of the block with name block_name_here if it finds it in the layout...anywhere. getChildHtml('block_name_here') get's you the html of the block with name block_name_here only if that block is a child of the current block. Here is an example. Consider the next layout section <block type="core/template" ...


27

I find it in devdocs of Magento2 Static Test To improve security against XSS injections, a static test XssPhtmlTemplateTest.php is added to dev\tests\static\testsuite\Magento\Test\Php. This static test finds all echo calls in PHTML-templates and determines if it is properly escaped or not. It covers the following cases: /* @noEscape */ before output. ...


27

First of all, we need to know how to create a custom theme Magento 2, we can more here: http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/themes/theme-create.html After creating a new custom theme. We're going to create new custom layout for our homepage. For example, our folder structure: We should focus on two xml files: layouts.xml and ...


25

The most relevant parts for you in this case are: Template file (.phtml) and Blocks While the template files include the basic HTML output, which is a combination of PHP and HTML (thus .phtml), the blocks are interacting with the Magento system to retrieve data from models. Example: The file which creates the HTML output for the product pages is app/...


25

I have resolved this issue now. The problem was the name of the view folder: app\code\MagicPack\Magicheader\View\frontend\templates\magicheader.phtml This needed to be: app\code\MagicPack\Magicheader\view\frontend\templates\magicheader.phtml With a small case "v". Hope that helps someone in the future.


23

These are all located in your theme directory. If looks like you are talking specifically about the product details page, so the main one to change would be located in your themes catalog/product/view.phtml. Since you do seem to be brand new to Magento, I would recommend you get to understand the basic design concepts of Magento. This guide should help ...


23

My approach is a little different but probably more future proof, in case of adding new tabs later on and changing the priority/order of these tabs. I passed an argument for each tab via XML File in my themes XML file ... <arguments> <argument name="priority" xsi:type="string">REPLACE WITH SOME NUMBER</argument> </arguments> ... ...


23

In Magento 2.3.1 or Above we can use sort_order argument in "app/design/frontend/Packagename/themename/Magento_Catalog/layout/catalog_product_view.xml" xml config <referenceBlock name="product.info.description"> <arguments> <argument name="title" translate="true" xsi:type="string">Description</argument> <...


21

You can do it by two ways: Using cli: goto you project root directory on command line and run below command php bin/magento dev:template-hints:enable php bin/magento dev:template-hints:disable go to admin backend: Store > Configuration > Advanced > Developer > Debug > Enabled Template Path Hints for Storefront > Yes Stores > Configuration > ...


21

Don't. This is like using ObjectManager::getInstance()->create() in a template! Use a custom Block that receives the helper as a constructor dependency instead, and add a proxy method that calls the helper method. In the template: $block->customMethod() In the block: public function __construct(Path/To/Helper/Class $helperClass, ...other ...


20

Go to admin For Front End: Stores > Configuration > Advanced > Developer > Debug > Enabled Template Path Hints for Storefront > Yes For Admin : Stores > Configuration > Advanced > Developer > Debug > Enabled Template Path Hints for Admin > Yes


20

you need to use the instance of \Magento\Framework\App\Config\ScopeConfigInterface in your block: Create the method getStoreName() public function getStoreName() { return $this->_scopeConfig->getValue( 'general/store_information/name', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } and call in your template echo $this-&...


20

Add these file in any of your custom module : app/code/Vendor/ModuleName/etc/module.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Vendor_ModuleName" setup_version="2.0.0" /> </config> app/code/...


19

Just reference necessary block and set template as attribute of referenceBlock node: <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="customer_form_register" template="...


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