1. pages
Sometimes, you want to use information like title or content from a CMS page (or multiple CMS pages) in another page. For example, you want to show a part of “Welcome” page in homepage. How can you do the task?
Today I will show you that how you can use CMS pages in another page.
To use information of a CMS page in another page, you will need the identifier (URL key) of this CMS page. Then in the page you want to use the information, put some codes as following:
$aCmsPage = Mage::getModel('cms/page')->load('URL-key-of-this-page', 'identifier');
$theTitle = $aCmsPage->getTitle();
$theContent = $aCmsPage->getContent();
Then you can use this title and content anywhere you want!
To get information from multiple CMS pages, we need to use CMS page collection:
$collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());
$collection->getSelect()->where('is_active = 1'); // use the filter in the case you want to get only enabled CMS pages.
foreach ($collection as $page) {
$theIdentifier = $page->getIdentifier();
$theTitle = $page->getTitle();
$theContent = $page->getContent();
....// use these like you want!
}
Thats it ! Let try and enjoy!
from: http://miragedesign.net/newss/magento-use-cms-page-in-another-page/
2. static block
Magento has made it really easy to get Static Content from within a CMS page with the use of widgets, but say you’re developing a custom theme, you may want to call a static block programmatically in a Magento theme in which case there are a few methods of doing so…
The first is quick and easy to drop into a Magento theme, but only gets the static block content:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('indentifer')->toHtml() ?>
Where, by calling the static block model, you can then get all fields associated with that block such as the static block title
<?php
$block = Mage::getModel('cms/block')->load('identifier');
echo $block->getTitle();
echo $block->getContent();
?>
Add a CMS Static Block to a page:
Within Magento:
{{block type="cms/block" block_id="identifier"}}
You want add static Block in xml file inside :
<block type="cms/block" name="BLOCK_NAME" after="cart_sidebar">
<action method="setBlockId"><block_id>IDENTIFIER</block_id></action>
</block>
Hope this helps you with static blocks in your custom magento theme. Happy coding!
from: http://thinkclay.com/technology/get-static-block-in-magento
分享到:
相关推荐
Ability to place any block in any position by easily changing CMS page layout Unlimited number of blocks inside each position Unlimited number of content items inside each block Block items can ...
Magento 系统请求响应流程图解析 Magento 是一个强大的 PHP 开源框架,作为一名 IT 行业大师,我将详细地解析 Magento 系统请求响应流程图,并对每个步骤进行详细的分析。 步骤 1:用户向浏览器发出请求 在整个...
这段代码的核心是`createBlock`方法,它用于创建一个指定类型的布局块,此处类型为`cms/block`,表示我们想要创建的是一个CMS静态块对象。接下来的`setBlockId`方法则用于设置要加载的静态块的ID,本例中为`...
Block类在模块的`Block`目录下创建,通常与Model和Template一起工作,形成数据获取、处理和展示的完整流程。 2. **Block的生命周期** Block的生命周期包括创建、初始化、加载数据和渲染等步骤。在Magento中,Block...
Athlete Magento主题,兼容Magento 1.9.x, 1.8.x, 1.7.x ,特点:完全自适应(响应式布局),自定义子主题,无限颜色,完全自定义,一键安装演示,小工具化横幅系统,颜色选择,MEGA菜单,多商店支持,自定义产品...
magento的关于自定义后台配置的简单示例 把Exercise_Avatar.xml放到magento/app/etc/modules/下面 文件夹Avatar放到magento/app/code/local/Exercise/下面就可以到后台看到相应配置信息
在电子商务领域,Magento是一款颇受欢迎的开源平台,它提供了丰富的功能和灵活性,使得商家能够创建和管理复杂的在线商店。为了进一步增强其功能性和用户体验,Magento社区开发了众多插件,这些插件覆盖了从SEO优化...
Magento多客户在同一Magento代码库上托管多个客户端。 每个客户端都有自己的local.xml和etc/modules.xml 。 这使您可以为每个客户端指定单独的数据库和缓存服务,以及根据要求启用/禁用模块。 每个客户保持独立性,...
app/code/local/App/Configviewer/Block app/code/local/App/Configviewer/controllers app/code/local/App/Configviewer/etc app/code/local/App/Configviewer/Helper app/code/local/App/Configviewer/Model ...
8. **清理缓存**:完成上述步骤后,别忘了清理Magento的布局和Block缓存,以便系统能识别新的改动。 通过以上步骤,你将能够在Magento中成功创建一个显示Bestseller产品的自定义页面。这个过程涉及到了Magento的...
在Magento中,处理用户登录状态和获取登录用户的信息是一项基本但至关重要的任务,这不仅关系到用户体验,还涉及到安全性、个性化推荐等多个方面。 ### Magento判断用户登录状态 在Magento中,判断用户是否已经...
Get a detailed insight into the structure of Magento Learn about event/observer-driven modules Get a hands-on introduction to custom shipping and payment methods ☆ 出版信息:☆ [作者信息] Branko ...
这里,`/path/to/source/magento/`是源站点的Magento根目录,`/path/to/destination/`是目标服务器的目录。 在新服务器上安装MySQL,并导入先前备份的数据库: ```bash mysql -u [new_username] -p[new_password] ...
Magento的后台菜单主要由` Mage_Adminhtml_Block_Menu`类控制,它通过遍历系统配置中的`adminhtml/menu`节点来生成菜单。每个菜单项都是一个XML节点,例如: ```xml 自定义模块</title> <sort_order>100</...
价值80美金的国外专业模板,免费下载: 模板演示: http://themeforest.net/item/metro-responsive-magento-theme/full_screen_preview/3614985 包括安装说明
### Magento通过产品名称获取产品ID的实现原理 在Magento中,每一件商品都有一个唯一的ID,这个ID是用于系统内部识别商品的主要依据。然而,在实际操作中,我们可能只知道产品的名称,而不知道其ID。这时,就需要...
app/code/local/Vendor/HelloWorld/Block app/code/local/Vendor/HelloWorld/Helper app/code/local/Vendor/HelloWorld/Model app/code/local/Vendor/HelloWorld/sql app/code/local/Vendor/HelloWorld/Model/...
3. **Block**: 这是视图层的业务逻辑,可能会添加新的Block类或修改现有Block来显示商品图片。 4. **View**: 包含模板文件,这里可能需要修改订单详情页面的HTML模板,以便在适当的位置插入图片。 5. **Helper** ...
app/code/local/App/Configviewer/Block app/code/local/App/Configviewer/controllers app/code/local/App/Configviewer/etc app/code/local/App/Configviewer/Helper app/code/local/App/Configviewer/Model app/...
Magento2x-Ubuntu-Nginx 如何使用Nginx在Ubuntu上安装Magento 2.3...- You can check the requirements system for Magento 2.3 in the link https://devdocs.magento.com/guides/v2.3/install-gde/prereq/nginx.html