How to add WYSIWYG Editor in Magento system configuration? - magento

I want to add WYSIWYG editor in Magento system configuration.
And also get the value from the that is there option to do this.
Cheers.

I have found the answer from this post. Thanks to Marius for giving this answer.
First of all add this in any layout file, to load the editor in the config section:
<adminhtml_system_config_edit>
<update handle="editor"/>
<reference name="head">
<action method="setCanLoadTinyMce"><load>1</load></action>
</reference>
</adminhtml_system_config_edit>
Now create your own field renderer. It has to be a block inside your module:
<?php
class Namespace_Module_Block_Adminhtml_System_Config_Editor extends Mage_Adminhtml_Block_System_Config_Form_Field implements Varien_Data_Form_Element_Renderer_Interface{
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element){
$element->setWysiwyg(true);
$element->setConfig(Mage::getSingleton('cms/wysiwyg_config')->getConfig());
return parent::_getElementHtml($element);
}
}
Now for the element inside the system.xml set the frontend_type 'editor' and the frontend_model your new block
<fieldname translate="label">
<label>Field label </label>
<frontend_type>editor</frontend_type>
<frontend_model>module/adminhtml_system_config_editor</frontend_model>
<sort_order>150</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</fieldname>
There are some issues when changing the config scope to a website or a store view. The textarea does not become 'disabled'. But if you can ignore this, you can use it without any problems.

What you need to do, is add a WYSIWYG editor with its appropriate adminhtml controller. After this, you can load the editor for every configfield you specify.
Try reading this article. It is a step-by-step guide how to add the editor.

Related

Magento custom head code

How can I add a custom code i.e. Facebook retargetting or conversion pixel, etc. to a section of a SPECIFIC page? (not global)
I am using the latest magento version.
Thanks
You can accomplish this cleanly using Magento’s layout system. Create or modify the local.xml file in your current theme’s layout subdirectory. Add a new layout update like this:
<!-- Add Facebook retargeting pixel on success page. -->
<checkout_onepage_success>
<reference name="before_body_end">
<block type="core/template" name="fb_retargeting" template="tracking/fb_retargeting.phtml"/>
</reference>
</checkout_onepage_success>
Notice that this layout update is targeting the <checkout_onepage_success> handle, which corresponds to the /checkout/onepage/success page. If you need to target a different page, you have to figure out the layout handle for that page. The handle is created by combining the route name, controller name, and controller method into a single underscore-separated string.
Now you just need to create your template file in your current design’s template subdirectory. In my above example, the template being referenced should be created at: app/design/frontend/.../template/tracking/fb_retargeting.phtml. You would just put the markup for your tracking pixel in that file.
1) If its going to be a CMS pages you can add in the design tab Layout Update XML and add custom xml code, for example
<reference name="head">
<block type="module/block" name="module" template="module/view.phtml" ></block>
</reference>
2) If this need to be in other pages, you can add same code in local.xml of your theme file
go to app/design/frontend/base/your theme/template/page/html/head.phtml
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
$url = Mage::getSingleton('core/url')->parseUrl($currentUrl);
$path = $url->getPath();
if($path == your specic page url){
your code.
}

How to add new layout via local.xml?

How can I add a new layout in magento using local.xml? I want it to appear in layouts list when I make new CMS page.
Layout in magento using local.xml
please go and follow this code.
http://www.codeboss.in/web-funda/2009/07/07/create-new-layout-in-magento/
Look at the very last block of code on this page. You can go into app/code/core/Mage/Page/etc/config.xml and add lines like this:
<TEMPLATE_LABEL module="page" translate="label">
<label>TEMPLATE NAME</label>
<template>page/TEMPLATE-FILENAME.phtml</template>
<layout_handle>page_HANDLE_NAME</layout_handle>
</TEMPLATE_LABEL>
replacing the capitalized words, e.g.
<home_format module="page" translate="label">
<label>Home Format</label>
<template>page/home-page.phtml</template>
<layout_handle>page_home_format</layout_handle>
</home_format>
Right before the end of the <page> ... </page> block of code.
Note: if you do it this way, you may not be able to upgrade Magento without losing your custom layout, as config.xml is a core file.

Magento dynamic text in layout xml file using addText

I currently have this:
<block type="core/text" name="top.address" as="topAddress">
<action method="addText"><text>PO BOX 1124, Rockdale, Sydney, NSW 2216, Australia</text></action>
</block>
But, when I need to update address, I have to do it manually here in the layout file. I want to pull address from store config ( general/store_information/address ) so, I can update everywhere on the site from one location easily.
I guess it can be done directly on the template like this:
<?php echo Mage::getStoreConfig('general/store_information/address') ?>
But I want to try with layout, is it possible?
Thanks.
My answer might be to oudated, but I faced with such problem just now I found an alternative way to solve it:
In layout you can specify core/text block and set its text via helper. You can use any suitable reference.
<reference name="before_body_end">
<block type="core/text" name="some.config">
<action method="addText">
<text helper="module_name/data/getSomeConfig" />
</action>
</block>
</reference>
Declare getSomeConfig function in the helper:
public function getSomeConfig()
{
return Mage::getStoreConfig('your_config_path');
}
In a such way you can even pass some dynamic data into javascript code.
Short answer - no. There is no functionality for it. That's not to say that it couldn't be done. There is an attribute that you can use on an action tag - ifconfig. It looks to see if a system config flag is set, and if it returns true, then it will proceed with the action. You could override or extend Mage/Core/Model/Layout.php to add that functionality.
There are a number of options to this problem, though.
You can use templates, like you mentioned.
If you are wanting to avoid a template, you can create a block that extends Mage_Core_Block_Text and specify the _toHtml method, with the code that you provided.
The best: I would see creating a generic block in a generic module that is used to pull system config requests and output them as text. You could either have it be a custom action/method, or send along an attribute value, which will end up in the data array for the block, which you could then lookup in _toHtml.

Change template page layout on cart page in Magento

Please help me on this. I want to change template page layout of cart page in magento.
The following is the URL : http://www.wildgoosetrading.com/index.php/checkout/cart/
I want this to look like other pages of category.
Thanks in advance.
You'd set the template for the cart in your checkout.xml layout file.
In the checkout_cart_index section (straight after <default>) look for the following block and change the template the cart page is using;
<!-- Mage_Checkout -->
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
EDIT
I know this is the accepted answer but soipo's answer is the better way. Apply the change to local.xml, don't modify the core layout files, override them using local.xml in your theme's layout. See http://www.classyllama.com/development/magento-development/the-better-way-to-modify-magento-layout
In your local.xml file you can just add the following:
<checkout_cart_index translate="label">
<reference name="root">
<action method="setTemplate"><template>page/3columns.phtml</template ></action >
</reference>
Just change the template to the one you need.
By using Magento's common setTemplate method, the inherent granularity introduced by Magento's own app/design/frontend/base/default/layout/checkout.xml is lost.
Magento deliberately created two methods for doing this: setCartTemplate and setEmptyTemplate. They handle two separate conditions.
One condition is when the cart has items, the other is when the cart is empty. By calling setTemplate, that granularity is lost. That means a cart with items and a cart with zero items will both display the same template, which might be not desired.
More on this can be found here: https://stackoverflow.com/a/33875491/2973534

In Magento, can I add a static block to the header by xml only?

I am trying to customize a theme using only local.xml whenever possible. I want to add a static block to the header without modifying header.phtml. This code works fine for the content area, but not for the header:
<default>
<reference name="content">
<block type="cms/block" name="how-it-works-button">
<action method="setBlockId"><block_id>how-it-works</block_id></action>
</block>
</reference>
</default>
Anybody know why? I thought that all I would need is to change “content” to “header”, but nothing shows up when I do.
Thanks for your help!
The content block is a special block known as a core/text_list block (PHP class Mage_Core_Block_Text_List). These blocks will automatically render out any child blocks that are added to them.
The header block, on the other hand, is a page/html_header block (PHP class Mage_Page_Block_Html_Header). This block class inherits from Mage_Core_Block_Template, making it a core/template block. Template blocks will only render sub-blocks if their corresponding phtml template requests the block. So, by adding your block to the header, you're only doing half the work you need to. You'll need to create a custom phtml template.
The simplest way to do this (post 1.4.1.1 is to, in your own theme, create a file at
template/page/html/header.phtml
And then at the end of this file add
<?php echo $this->getChildHtml('how-it-works-button'); ?>
Assuming you've added a block to header block via layout xml, this should render your template.
Please Try this
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('how-it-works')->toHtml() ?>
And this code in header.phtml
add output="toHtml" in the block tag. I think it is only that.

Resources