fondof/magento-module-fondof-contentful

一个用于集成Contentful的Magento模块

dev-master 2018-04-10 06:34 UTC

This package is auto-updated.

Last update: 2019-12-19 14:40:22 UTC


README

Magento Contentful集成

Build Status PHP from Travis config license

描述

Contentful的核心特性包括

  • 通过路由器渲染预定义的内容类型
    • 作为页面(即将推出)
    • 通过小部件(即将推出)
  • 将模板文件分配给内容类型
  • 缓存API结果
  • 缓存HTML输出

安装

通过modman

打开命令行并运行以下命令

cd PATH_TO_MAGENTO_ROOT
modman init
modman clone git@github.com:fond-of/magento-module-fondof-contentful.git

通过composer

打开命令行并运行以下命令

cd PATH_TO_MAGENTO_ROOT
composer require fondof/magento-module-fondof-contentful

通过存档

  • 下载ZIP存档
  • 解压文件
  • 将解压的文件复制到PATH_TO_MAGENTO/

使用modman或composer时,必须启用“允许符号链接”设置。模块安装后,必须清除缓存。

教程

如何将模板文件分配给特定内容类型

如果你的主题中有“local.xml”文件,请编辑其中的默认部分。

<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
    <default>
        ...
        
        <reference name="fondof_contentful_navigation_item_renderers">
            <action method="addContentTypeRenderer">
                <contentType>contentTypeApiIdentifier</contentType>
                <blockType>fondof_contentful/content_type_renderer_xxx</blockType>
                <template>fondof/contentful/content_type_api_identifier.phtml</template>
            </action>
        </reference>
    </default>
</layout>

作为替代方案,你也可以覆盖布局文件“fondof_contentful.xml”(复制到app/design/frontend/your_package/your_theme/layout/)。使用“fondof_contentful/content_type_renderer”的块声明为特定内容类型分配模板。

<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
    <default>
        <block type="fondof_contentful/content_type_renderer" name="fondof_contentful_content_type_renderer">
            <action method="addContentTypeRenderer">
                <contentType>contentTypeApiIdentifier1</contentType>
                <blockType>fondof_contentful/content_type_renderer_xxx</blockType>
                <template>fondof/contentful/content_type_api_identifier_1.phtml</template>
            </action>
            ...
            <action method="addContentTypeRenderer">
                <contentType>contentTypeApiIdentifierN</contentType>
                <blockType>fondof_contentful/content_type_renderer_xxx</blockType>
                <template>fondof/contentful/content_type_api_identifier_n.phtml</template>
            </action>
        </block>
    </default>

    <fondof_contentful_page_view>
        <reference name="root">
            <action method="setTemplate"><template>page/1column-full.phtml</template></action>
        </reference>

        <reference name="content">
            <block type="fondof_contentful/page" name="fondof_contentful_page"/>
        </reference>
    </fondof_contentful_page_view>

    <fondof_contentful_index_index translate="label">
        <label>FOB Contentful Home Page</label>

        <reference name="root">
            <action method="setTemplate"><template>page/1column-full.phtml</template></action>
        </reference>

        <reference name="content">
            <block type="fondof_contentful/page" name="fondof_contentful_page"/>
        </reference>
    </fondof_contentful_index_index>
</layout>

如何在模板中访问内容模型

块"FondOf_Contentful_Block_Content_Type_Renderer_Default"提供了"getContent"方法。通过调用此方法,你可以完全访问内容模型。

如何调整来自Contentful的图片大小

将参数w(代表宽度)或h(代表高度)添加到要调整大小的图片URL中。例如

URL 宽度 高度
http://url-to-image/example.jpg?w=100 100px auto
http://url-to-image/example.jpg?h=100 auto 100px
http://url-to-image/example.jpg?w=100&=100 100px 100px

如何渲染子内容

如果你要渲染子内容,请使用“FondOf_Contentful_Block_Content_Type_Renderer_Default”块的“getContentHtml”方法。

<?php $content = $this->getContent(); ?>
<div ...>
    ...
    <?php echo $this->getContentHtml($content->getTeaser()); ?>
    ...
</div>