### Magento Connect CLI Install (1.5+)
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/j_magento_connect.markdown
Commands for installing and uninstalling Magento extensions using the 'mage' script for Magento 1.5 and later. This covers making the script executable, setup, and package installation/uninstallation.
```shell
chmod +x mage
./mage mage-setup
./mage install-file No_Frills_Magento_Layout_3_start-1.0.0.tgz
./mage uninstall community No_Frills_Magento_Layout_3_start
```
--------------------------------
### Magento Connect CLI Install (1.4x)
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/j_magento_connect.markdown
Commands for installing and uninstalling Magento extensions using the custom PEAR installer script for Magento 1.4.2. This includes making the script executable and performing installations.
```shell
chmod +x pear
./pear mage-setup
./pear install No_Frills_Magento_Layout_1_start-1.0.0.tgz
./pear uninstall channel://connect.magentocommerce.com/community/No_Frills_Magento_Layout_1_sta...
```
--------------------------------
### Enabling and Upgrading Magento Module
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-install-module.md
These commands are used to enable the newly installed Pulsestorm_Nofrillslayout module and then upgrade the Magento setup to apply the changes. The `module:enable` command registers the module, and `setup:upgrade` updates the database schema and data.
```php
php bin/magento module:enable Pulsestorm_Nofrillslayout
php bin/magento setup:upgrade
```
--------------------------------
### Find 'out example'
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/bin/editing-regex.txt
This `ack` command searches for the phrase 'out example', ignoring case. It's useful for finding specific examples related to the word 'out' within the project's documentation.
```bash
ack -i '\bout example'
```
--------------------------------
### Theme Template File Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-5-themes.md
This example shows a simple phtml template file that can be placed directly within a theme's 'templates' directory. Magento will render this template when referenced by a layout file without a module prefix.
```html
Hello Category Listing Page.
```
--------------------------------
### Manual Module Installation Structure
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/0_intro.markdown
This snippet illustrates the standard file and folder structure for a manual Magento module installation. It shows where the module files should be placed within the Magento directory.
```text
app/code/local/Nofrills_Magento
app/module/etc/Nofrills_Magento.xml
app/.....
```
--------------------------------
### Example CSS File Content
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-7-frontend-css.md
This is a simple example of a CSS file that can be added to a Magento module. When included, it will apply the specified styles to the page.
```css
body {
background-color:#f00;
}
```
--------------------------------
### Magento Web Root Examples
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-7-frontend-css.md
Illustrates the different URL structures for static assets depending on the Magento web root configuration.
```php
http://magento.example.com/pub/static/...
vs.
http://magento.example.com/static/...
```
--------------------------------
### PHP System Configuration Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/i_system_config.markdown
Demonstrates a simple PHP array-based system configuration, storing key/value pairs.
```php
$config['db_name'] = 'localhost';
$config['db_password'] = '12345';
$config['logo'] = 'awesomelogo.gif';
etc.
```
--------------------------------
### Magento Module Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/0_intro.markdown
This snippet demonstrates the typical structure and naming convention for a Magento module, specifically 'Nofrills_Booklayout', used for distributing example code throughout the book. It highlights how modules are created to add functionality to a Magento system.
```PHP
namespace Nofrills\Booklayout;
// Example class within the module
class ExampleClass
{
public function doSomething()
{
// Module logic here
}
}
```
--------------------------------
### CSS File Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-5-themes.md
A simple example of a CSS file content that would be used to override a default Magento CSS file.
```css
body{
background-color:#f00;
}
```
--------------------------------
### Example Generated styles-l.css with Custom Rules
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-5-themes.md
Presents a snippet of a generated styles-l.css file, showing how custom Less rules added via //@magento_import directives are integrated into the final compiled CSS.
```css
/* Generated styles-l.css file */
/* ... */
@media only screen and (min-device-width: 320px) and (max-device-width: 780px) and (orientation: landscape) {
.product-video {
height: 100%;
width: 81%;
}
}
body.example-less-rule-base-css-folder {
background-color: #f00;
}
@media all and (min-width: 768px), print {
.abs-product-options-list-desktop dt,
/* ... */
```
--------------------------------
### Instantiate Two Template Blocks
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-1-blocks-template-php.md
This example shows the instantiation of two separate template blocks, assigning a specific template file to each. It highlights the initial setup before establishing a parent-child relationship.
```php
public function execute()
{
$objectManager = $this->getObjectManager();
$layout = $objectManager->get('Magento\Framework\View\Layout');
$blockParent = $layout->createBlock('Magento\Framework\View\Element\Template');
$blockParent->setTemplate('Pulsestorm_Nofrillslayout::chapter1/parent.phtml');
$blockChild = $layout->createBlock('Magento\Framework\View\Element\Template');
$blockChild->setTemplate('Pulsestorm_Nofrillslayout::chapter1/child.phtml');
echo $blockParent->toHtml();
echo $blockChild->toHtml();
}
```
--------------------------------
### Install Grunt CLI Globally
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-frontend-build.md
Installs the Grunt command-line interface globally, making the 'grunt' command accessible from any directory.
```bash
$ npm install -g grunt-cli
grant-cli v1.2.0
```
--------------------------------
### Layout XML Structure Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-6-advanced-xml-loading.md
Provides an example of the Page Layout XML structure used by Magento, including body and head elements.
```xml
```
--------------------------------
### Basic Javascript Alert
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-8-frontend-javascript.md
A simple Javascript file that displays a 'Hello World' alert box when executed. This is the most basic example of a frontend script in Magento.
```javascript
alert("Hello World");
```
--------------------------------
### Magento Layout Rendering
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/1_building_layouts_programatically.markdown
Demonstrates how to create a block, add it to the layout, set direct output, and get the page output in Magento.
```php
public function layoutAction()
{
$layout = Mage::getSingleton('core/layout');
$block = $layout->createBlock('nofrills_booklayout/helloworld','root');
$layout->addOutputBlock('root');
$layout->setDirectOutput(true);
$layout->getOutput();
}
```
--------------------------------
### Copy Magento Configuration Files
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-frontend-build.md
Copies sample configuration files for npm ('package.json.sample' to 'package.json') and Grunt ('Gruntfile.js.sample' to 'Gruntfile.js') to enable local project setup and build execution.
```bash
cd /path/to/magento
cp package.json.sample package.json
cp Gruntfile.js.sample Gruntfile.js
```
--------------------------------
### Magento Module Registration Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-5-themes.md
This PHP snippet demonstrates the standard way a Magento module registers itself with the ComponentRegistrar. This is crucial for Magento to identify the module and its associated files, including layout files.
```php
setXml($xml);
```
--------------------------------
### Magento Layout Update XML Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/4_bringing_it_together.markdown
Illustrates a typical structure for Magento Layout Update XML files, used to define page structure and block rendering.
```xml
```
--------------------------------
### Magento Component Registration Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-components.md
An example of a `registration.php` file used by Magento to register a component. The `ComponentRegistrar::register` method specifies the component type (e.g., MODULE) and its name, linking it to the directory where the file resides.
```php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Someotherpackage_Module',
__DIR__
);
```
--------------------------------
### Build Magento Layout Project
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/README.md
This snippet shows the command to execute for building the Magento Layout No Frills project. It requires specific dependencies to be installed beforehand.
```bash
% php build.php
```
--------------------------------
### Magento PHTML Template Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/1_building_layouts_programatically.markdown
A sample PHTML template file for Magento, demonstrating how to display fetched titles, hardcoded content, and child block HTML. It includes comments for file location.
```html
fetchTitle(); ?>
Hello World 2
getChildHtml(); ?>
The second paragraph is hard-coded.
```
--------------------------------
### Magento Layout Object Initialization
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/1_building_layouts_programatically.markdown
Demonstrates a common pattern in Magento for initializing the layout object within a controller, abstracting the setup process into a dedicated method.
```php
class SomeController {
protected function _initLayout() {
// Layout object instantiation and setup logic
$layout = $this->getLayout();
// ... further configuration ...
return $layout;
}
public function indexAction() {
$layout = $this->_initLayout();
// ... render layout ...
}
}
```
--------------------------------
### XML Layout Update Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-2-layout-xml.md
An example of a simple XML layout update that defines a container with a name and label. This XML is processed by Magento's layout system.
```xml
```
--------------------------------
### Template for Rendering Multiple Child Blocks
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/1_building_layouts_programatically.markdown
The corresponding template file for the previous PHP example, showing how to render specific child blocks using `getChildHtml`.
```html
```
--------------------------------
### Custom Block Rendering in Magento
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/1_building_layouts_programatically.markdown
Illustrates creating a custom block using a class alias ('nofrills_booklayout/helloworld') and rendering it. This example assumes a corresponding block class exists.
```php
public function layoutAction()
{
$layout = Mage::getSingleton('core/layout');
$block = $layout->createBlock('nofrills_booklayout/helloworld','root');
echo $block->toHtml();
}
```
--------------------------------
### Getting Help for Magento CLI Commands
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-cli.md
This command provides detailed help information for a specific Magento CLI command, including its arguments and options.
```bash
$ php bin/magento help module:enable
```
--------------------------------
### Magento Module Configuration Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/c_appendix_creating_modules.markdown
This snippet shows the basic structure of a Magento module's configuration within config.xml, including the module name, activation status, and code pool.
```xml
truelocal
```
--------------------------------
### Instantiate and Output a Simple Text Block
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/1_building_layouts_programatically.markdown
This snippet demonstrates how to instantiate a Mage_Core_Block_Text object, set its text content, and then output the HTML representation. This is a basic example of programmatic block rendering in Magento.
```php
public function indexAction()
{
$block = new Mage_Core_Block_Text();
$block->setText("Hello World");
echo $block->toHtml();
}
```
--------------------------------
### Magento Page Layout Configuration Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/6_cms_page.markdown
Shows a typical configuration node for a page layout in Magento's layout XML, defining the label, template file, and associated layout handle.
```xml
page/2columns-left.phtml
page_two_columns_left
```
--------------------------------
### Build Magento Layout
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/README.md
This snippet shows the command to initiate the build process for the Magento 1 Layout project. It requires a PHP environment and a LaTeX installation with pdflatex.
```bash
% ./bin/build.bash
```
--------------------------------
### Command with Options
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-cli.md
Shows how to use options with command-line programs to modify their behavior. The 'ls -1' command is used to get a single-column listing of files.
```bash
$ ls -1
```
--------------------------------
### Listing Magento CLI Commands
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-cli.md
This command lists all available commands within the Magento CLI framework. It's the starting point for exploring the CLI's capabilities.
```bash
$ php bin/magento list
```
--------------------------------
### Pseudo-code for x-magento-init Execution
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-8-frontend-javascript.md
Provides a pseudo-code representation of how Magento's bootstrap process handles `x-magento-init` tags, loading the specified RequireJS module and executing it with the provided configuration.
```javascript
var moduleFunction = requirejs('mage/cookies');
moduleFunction({"expires": null,
"path": "/",
"domain": ".magento.example.com",
"secure": false,
"lifetime": "3600"});
```
--------------------------------
### LessCSS File Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-5-themes.md
A simple example of a LessCSS file content that would be used to override a default Magento LessCSS file.
```less
body{
background-color:#f00;
}
```
--------------------------------
### Basic LessCSS File Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-7-frontend-css.md
A simple LessCSS file that defines a blue background color for the body element. This file is processed by Magento when referenced in the layout XML.
```less
@myBlue: #00f;
body {
background-color:@myBlue;
}
```
--------------------------------
### x-magento-init Script Tag Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-8-frontend-javascript.md
Demonstrates the usage of `
```
--------------------------------
### Modified Magento Product Attribute Template
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-5-themes.md
This is a modified version of the product attribute template, demonstrating how to insert custom content. The example adds 'This is an attribute:' text before the attribute label and value.
```php
helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
$_call = $block->getAtCall();
$_code = $block->getAtCode();
$_className = $block->getCssClass();
$_attributeLabel = $block->getAtLabel();
$_attributeType = $block->getAtType();
$_attributeAddAttribute = $block->getAddAttribute();
if ($_attributeLabel && $_attributeLabel == 'default') {
$_attributeLabel = $_product->getResource()->getAttribute($_code)->getFrontendLabel();
}
if ($_attributeType && $_attributeType == 'text') {
$_attributeValue = ($_helper->productAttribute($_product, $_product->$_call(), $_code)) ? $_product->getAttributeText($_code) : '';
} else {
$_attributeValue = $_helper->productAttribute($_product, $_product->$_call(), $_code);
}
?>
This is an attribute:
>
```
--------------------------------
### Magento Installation Block Hierarchy
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/a_appendix_blocks.markdown
This snippet details the block structure for the Magento installation process, covering various stages from beginning to end.
```php
Mage_Install_Block_Abstract
|-- Mage_Install_Block_Admin
|-- Mage_Install_Block_Begin
|-- Mage_Install_Block_Config
|-- Mage_Install_Block_Download
|-- Mage_Install_Block_End
`-- Mage_Install_Block_Locale
Mage_Install_Block_State
```
--------------------------------
### Magento Layout Update XML Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/6_cms_page.markdown
Example of adding a custom block ('redundant') to the 'content' reference using Layout Update XML in Magento.
```xml
Hello Again
```
--------------------------------
### Magento Layout Object Initialization and Block Creation
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/1_building_layouts_programatically.markdown
Demonstrates how to get a singleton instance of the Magento layout object and use it to create a block with a specified template. It also shows how to render the block's HTML.
```php
public function layoutAction()
{
$layout = Mage::getSingleton('core/layout');
$block = $layout->createBlock('core/template','root');
$block->setTemplate('helloworld-2.phtml');
echo $block->toHtml();
}
```
--------------------------------
### Knockout.js ViewModel Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-10-knockout-scopes.md
Illustrates a typical Knockout.js ViewModel constructor function as used in default examples and adopted by Magento for its frontend object system.
```javascript
function AppViewModel() {
this.firstName = "Bert";
this.lastName = "Bertington";
}
// Activates knockout.js
ko.applyBindings(new AppViewModel());
```
--------------------------------
### Magento Block Definition Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/7_widgets.markdown
An example of a Magento block definition in Layout Update XML, showing how a block is named and aliased, which is referenced in the widget configuration.
```xml
```
--------------------------------
### Magento Controller Action for Template Rendering
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/1_building_layouts_programatically.markdown
A basic Magento controller action that sets a template file ('helloworld.phtml') to a block and then renders the block's HTML output. This is a foundational example for displaying content from a template.
```php
public function indexAction()
{
$block = new Mage_Core_Block_Template();
$block->setTemplate('helloworld.phtml');
echo $block->toHtml();
}
```
--------------------------------
### ReferenceController.php - Layout Initialization and Output
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/2_page_layout.markdown
This snippet shows the core logic within a Magento controller for initializing a layout, loading XML updates, generating the layout XML, and rendering the output. It highlights the separation of concerns between layout setup and output.
```php
class Nofrills_Booklayout_ReferenceController
extends Mage_Core_Controller_Front_Action
{
/**
* Use to set the base page structure
*/
protected function _initLayout()
{
$path_page = Mage::getModuleDir('', 'Nofrills_Booklayout') . DS .
'page-layouts' . DS . 'page.xml';
$xml = file_get_contents($path_page);
$layout = Mage::getSingleton('core/layout')
->getUpdate()
->addUpdate($xml);
}
/**
* Use to send output
*/
protected function _sendOutput()
{
$layout = Mage::getSingleton('core/layout');
$layout->generateXml()
->generateBlocks();
echo $layout->setDirectOutput(false)->getOutput();
}
public function indexAction()
{
$this->_initLayout();
$this->_sendOutput();
}
}
```
--------------------------------
### Grunt Help
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-frontend-build.md
Displays a list of available tasks and options for the Grunt build tool.
```bash
$ grunt --help
```
--------------------------------
### Magento Source Model Example (Yes/No)
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/h_widget_field_rendering_options.markdown
An example of a Magento source model class that provides options for a select field. The 'toOptionArray' method returns an array of key-value pairs for the options.
```php
class Mage_Adminhtml_Model_System_Config_Source_Yesno
{
/**
* Options getter
*
* @return array
*/
public function toOptionArray()
{
return array(
array('value' => 1, 'label'=>Mage::helper('adminhtml')->__('Yes')),
array('value' => 0, 'label'=>Mage::helper('adminhtml')->__('No')),
);
}
}
```
--------------------------------
### Magento Controller with Layout Container and Blocks (Initial)
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-2-layout-xml.md
This PHP code snippet demonstrates a Magento controller's execute method. It initializes the layout object, adds a 'top' container, creates two template blocks, assigns them to the 'top' container, generates the layout structure, and outputs the result. This is the initial setup before introducing layout XML.
```php
public function execute()
{
$objectManager = $this->getObjectManager();
$layout = $objectManager->get('Magento\Framework\View\Layout');
$layout->addContainer('top', 'The top level container');
$blockOne = $layout->createBlock(
'Magento\Framework\View\Element\Template',
'pulsestorm_nofrills_chapter2_block1'
);
$blockOne->setTemplate('Pulsestorm_Nofrillslayout::chapter2/block1.phtml');
$blockTwo = $layout->createBlock(
'Magento\Framework\View\Element\Template',
'pulsestorm_nofrills_chapter2_block2'
);
$blockTwo->setTemplate('Pulsestorm_Nofrillslayout::chapter2/block2.phtml');
$structure = $layout->getStructure(); //note: not standard magento
$structure->setAsChild('pulsestorm_nofrills_chapter2_block1', 'top');
$structure->setAsChild('pulsestorm_nofrills_chapter2_block2', 'top');
$layout->generateElements();
echo $layout->getOutput();
}
```
--------------------------------
### Frontend Module RequireJS Configuration Dependencies
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-8-frontend-javascript.md
Example of a frontend module's requirejs-config.js file specifying dependencies to be loaded after RequireJS initialization. These dependencies often set up global state or configurations.
```javascript
var config = {
deps: [
"jquery/jquery.mobile.custom",
"js/responsive",
"mage/common",
"mage/dataPost",
"js/theme",
"mage/bootstrap"
]
}
```
--------------------------------
### Magento Empty Page Layout Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-4-page-layout.md
An example of a Magento page layout XML file (`empty.xml`) showcasing the liberal use of htmlTag and htmlClass attributes within nested container elements. This illustrates how these attributes contribute to the overall HTML structure of a page.
```XML
```
--------------------------------
### Magento Data Manipulation with Varien_Object
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/g_appendix_setters_and_getters.markdown
Demonstrates direct methods for getting and setting data within Magento objects that inherit from Varien_Object. Covers retrieving all data, setting a single key-value pair, getting a specific value, and setting multiple key-value pairs at once.
```php
/**
* Object attributes
*
* @var array
*/
protected $_data = array();
// Get all data as an array
var_dump($object->getData());
// Set a specific data field
$object->setData('the_key', 'value');
// Get a specific field back
$value = $object->getData('the_key');
// Set multiple keys at once
$object->setData(array(
'the_key' => 'value',
'the_thing' => $thing
));
```
--------------------------------
### Instantiate and Render a Template Block
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/1_building_layouts_programatically.markdown
This snippet shows how to create an instance of Mage_Core_Block_Template, assign a specific phtml template file to it, and then render the block's HTML output. This is a common pattern for integrating custom templates into Magento.
```php
public function indexAction()
{
$block = new Mage_Core_Block_Template();
$block->setTemplate('helloworld.phtml');
echo $block->toHtml();
}
```
--------------------------------
### Check Node.js Version
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-frontend-build.md
Verifies if Node.js is installed and displays its version using the '-v' flag.
```bash
$ node -v
v6.4.0
```
--------------------------------
### Creating a Magento phtml Template
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/1_building_layouts_programatically.markdown
Demonstrates the creation of a simple 'helloworld.phtml' template file in the default Magento theme. This file contains basic HTML content that will be rendered by a Magento block.
```php
Hello World
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum
```
--------------------------------
### Controller with Custom Handle Removed
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-3-layouthandles.md
An example of a controller's execute method where a custom layout handle has been commented out. This demonstrates the effect of not having a specific layout handle defined.
```php
public function execute()
{
$pageObject = $this->resultPageFactory->create();
//$pageObject->addHandle('our_custom_handle');
return $pageObject;
}
```
--------------------------------
### PHP Constructor Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-autoload.md
Demonstrates how referencing a Factory class in a constructor triggers Magento's autoloader to generate the class if it doesn't exist.
```php
public function __construct(SomeObjectFactory $factory)
{
/* ... */
}
```
--------------------------------
### Pseudo-code for data-mage-init Execution
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-8-frontend-javascript.md
Illustrates the internal process of Magento's bootstrapping when encountering a `data-mage-init` attribute. It loads the module specified in the attribute and calls its function with the associated configuration and the target DOM element.
```javascript
var moduleFunction = requirejs('dropdownDialog');
moduleFunction('{
"appendTo":"#switcher-currency > .options",
"triggerTarget":"#switcher-currency-trigger",
"closeOnMouseLeave": false,
"triggerClass":"active",
"parentClass":"active",
"buttons":null}', jQuery('#main-dropdown'));
```
--------------------------------
### Editing LessCSS File
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-7-frontend-css.md
Example of editing a LessCSS file to change styles. This is the initial step before cache clearing.
```less
#File: app/code/Pulsestorm/Nofrillslayout/view/frontend/web/chapter-7/example-2.less
@myBlue: #00a;
body {
background-color:@myBlue;
}
```
--------------------------------
### ViewModel Instantiation Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-10-knockout-scopes.md
Illustrates the underlying JavaScript code that Magento might use to instantiate a ViewModel with provided configuration values.
```javascript
var viewModel = new UiElement({
"component": "Pulsestorm_Nofrillslayout/chapter10/user/view-model",
"template": "Pulsestorm_Nofrillslayout/chapter10/user/hello-view-model",
"helloWorld":"Hola Muendo"
});
```
--------------------------------
### Check npm Version
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-frontend-build.md
Verifies if npm (Node Package Manager) is installed and displays its version using the '-v' flag.
```bash
$ npm -v
3.10.6
```
--------------------------------
### Inserting a Block After a Specific Block in a Reference
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/5_advanced_layout_features.markdown
Example of inserting a new block ('fakeline') after an existing block ('four') within the 'content' reference container.
```XML
]]>
```
--------------------------------
### Magento Block Rendering Process
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/4_bringing_it_together.markdown
Explains how Magento's block objects are instantiated and responsible for rendering HTML, often through template files or specific rendering methods.
```php
class Mage_Core_Block_Abstract {
protected $_template;
public function setTemplate($template) {
$this->_template = $template;
return $this;
}
public function getTemplate() {
return $this->_template;
}
protected function _toHtml() {
// Rendering logic, often involving include/render of template file
if ($this->_template) {
return $this->renderView($this->fetchView($this));
}
return '';
}
}
```
--------------------------------
### Find Files from Current Directory
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-unix-find.md
Searches for files matching a pattern starting from the current directory. The '.' symbol represents the current directory in Unix-like systems.
```unix
$ find . -name '*.phtml'
```
--------------------------------
### Extracting the Module Archive
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-install-module.md
This command extracts the Pulsestorm_Nofrills module from a gzipped tar archive. It assumes the archive file is named 'Pulsestorm_Nofrills.tar.gz' and is located in the current directory.
```bash
tar -zxvf Pulsestorm_Nofrills.tar.gz
```
--------------------------------
### Basic RequireJS Program
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-8-frontend-javascript.md
A simple RequireJS program with no module dependencies. It executes a callback function that displays an alert message.
```javascript
require([], function(){
alert("Hello RequireJS");
});
```
--------------------------------
### Magento Controller Action Layout Loading
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/4_bringing_it_together.markdown
Demonstrates how a controller action in Magento initiates the layout loading process, ultimately resulting in a Page Layout XML tree.
```php
public function viewAction() {
$this->loadLayout(); // Loads the layout handle associated with this action
// Further manipulation of the layout object can occur here
$this->renderLayout(); // Renders the layout and outputs the HTML
}
```
--------------------------------
### YouTube Widget Configuration Example
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/7_widgets.markdown
This snippet shows how to configure a YouTube widget in Magento, including setting the video ID and selecting a frontend template from a dropdown.
```xml
```
```xml
11youtube.phtmlselectyoutube.phtmlyoutube-as-link.phtml
```
--------------------------------
### Loading XML from Sample Folder
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-2-layout-xml.md
A helper method to load XML content from a specified path within the module's sample XML directory. It handles file loading, basic XML parsing using SimpleXML, and returns the XML content as a string, excluding the XML declaration.
```php
protected function loadXmlFromSampleXmlFolder($path)
{
$path = realpath(__DIR__) . '/../sample-xml/' . $path;
@$xml = simplexml_load_file($path);
if(!$xml)
{
throw new \Exception("Could not load valid XML from $path");
}
return str_replace('', '', $xml->asXml());
}
```
--------------------------------
### Magento Widget Directive Usage
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/7_widgets.markdown
Example of how to insert the configured YouTube widget into Magento content using a directive tag, specifying the widget type and its parameters.
```html
{{widget type="nofrills_booklayout/youtube" video_id="qYkbTyHXwbs"}}
```
--------------------------------
### Magento Package Layout Structure
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/4_bringing_it_together.markdown
Describes how Magento combines multiple XML files from its Package Layout repository to form a single Page Layout tree.
```xml
page/2columns-left.phtml
```
--------------------------------
### Setting Text Content and Inserting into Layout
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/1_building_layouts_programatically.markdown
Shows how to create a 'core/text' block, set its text content, retrieve a reference to another block (e.g., 'content'), and insert the text block into it. This illustrates dynamic content addition to a layout structure.
```php
$text = $layout->createBlock('core/text','words');
$text->setText('It was the best of times, it was the BLURST?! of times?');
$content = $layout->getBlock('content');
$content->insert($text);
```
--------------------------------
### Magento CSS Link Tags
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-7-frontend-css.md
Demonstrates how Magento includes CSS files in the HTML source, specifying media types for different screen sizes and print.
```html
```
--------------------------------
### Initializing Magento Layout and Adding Blocks
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/1_building_layouts_programatically.markdown
Demonstrates setting up a base layout object with common components and adding child blocks using the 'insert' method. It contrasts 'insert' with 'setChild', highlighting the automatic naming and internal array handling of 'insert'.
```php
$sidebar = $layout->createBlock('nofrills_booklayout/template','sidebar')
->setTemplate('simple-page/sidebar.phtml');
$content = $layout->createBlock('core/text_list', 'content');
$root = $layout->createBlock('nofrills_booklayout/template','root')
->setTemplate('simple-page/2col.phtml')
->insert($additional_head)
->insert($sidebar)
->insert($content);
return $layout;
```
--------------------------------
### Magento Layout Handle for Two Columns Left
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/6_cms_page.markdown
An example of a layout handle definition ('page_two_columns_left') used in Magento, which typically references the root block and sets its template.
```xml
page/2columns-left.phtml
```
--------------------------------
### Using getChildChildHtml in a Template
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-1/5_advanced_layout_features.markdown
Provides an example of how to use the `getChildChildHtml` method in a phtml template to render a specific child block ('foo') of a parent block identified by 'my_child'.
```php
getChildChildHtml('my_child', 'foo'); ?>
```
--------------------------------
### Get Magento Layout Update Manager
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-2-layout-xml.md
Fetches the Update Manager object from the layout object, which is responsible for managing XML layout updates.
```php
$updateManager = $layout->getUpdate();
```
--------------------------------
### Command with Arguments
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/appendix-cli.md
Illustrates how command-line programs can accept arguments, similar to functions in programming. The 'cd' command is shown changing the directory to '/path/to/magento'.
```bash
$ cd /path/to/magento
```
--------------------------------
### Find Default Layout XML Files
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-3-layouthandles.md
Searches the Magento vendor directory for all 'default.xml' layout files. These files are typically used for applying layout instructions on every page load.
```shell
$ find vendor/magento -wholename '*/module-*/default.xml'
```
--------------------------------
### Example Magento Static Asset URL
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-9-frontend-advanced-topics.md
Demonstrates a typical URL structure for static assets in Magento, highlighting the different segments that correspond to various configuration and theme elements.
```http
http://magento.example.com
/pub/static
/version1514092162
/frontend
/Magento
/luma
/en_US
/css
/styles-m.css
```
--------------------------------
### Magento Container with htmlTag
Source: https://github.com/astorm/magento-layout-no-frills/blob/main/magento-2/src/chapter-4-page-layout.md
Example of a Magento container block with the htmlTag attribute set to 'div'. This modifies the default container tag to a div, affecting the rendered HTML output.
```XML
```