mageprince / magento2-FAQ

This module adds an easy way to use FAQ Section to your Magento store with jQuery Accordion. In this module, admin can add and update FAQ. Admin can also create FAQ group with group icon.
57 stars 37 forks source link

Module Update #9

Closed trucatchtraps closed 6 years ago

trucatchtraps commented 6 years ago

Hi,

To anyone using this module or the developers themselves. I would recommend you add these changes in your custom theme. They both improve the overall aspect of the module.

Create Prince_Faq/layout and Prince_Faq/templates/index in your custom theme.

Upload the attached faq_index_index.xml file to the layout folder you created.

<?xml version="1.0" ?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

<head>
    <title>Frequently Asked Questions</title>
    <!-- <css src="Prince_Faq/css/faq.css"/> -->
    <!-- <link src="Prince_Faq/js/faq.js"/> --> 
</head>

    <body>

    <referenceBlock name="page.main.title">
        <action method="setPageTitle">
            <argument translate="true" name="title" xsi:type="string">Frequently Asked Questions</argument>
        </action>
    </referenceBlock>

    <referenceBlock name="breadcrumbs">
        <action method="addCrumb">
            <argument name="crumbName" xsi:type="string">Home</argument>
            <argument name="crumbInfo" xsi:type="array">
                <item name="title" xsi:type="string">Home</item>
                <item name="label" xsi:type="string">Home</item>
                <item name="link" xsi:type="string">{{baseUrl}}</item>
            </argument>
        </action>
        <action method="addCrumb">
            <argument name="crumbName" xsi:type="string">Frequently Asked Questions</argument>
            <argument name="crumbInfo" xsi:type="array">
                <item name="title" xsi:type="string">Frequently Asked Questions</item>
                <item name="label" xsi:type="string">Frequently Asked Questions</item>
            </argument>
        </action>
        </referenceBlock>

    <!-- 
    <referenceContainer name="content">
        <block class="Prince\Faq\Block\Index\Index" name="index.index" template="Prince_Faq::index/index.phtml"/>
    </referenceContainer>
    -->

    </body>
</page>

This file will add a Title and Breadcrumbs to the FAQ page. As well as removing the css and js that I am not using, due to lots of issues.

Upload the attached index.phtml file to the templates/index folder.

<?php $isEnable = $block->getConfig('faqtab/general/enable') ?>
<?php $showGroup = $block->getConfig('faqtab/general/showgroup') ?>
<?php $showGroupTitle = $block->getConfig('faqtab/general/showgrouptitle') ?>
<?php $faqGroupCollection = $block->getFaqGroupCollection() ?>
<?php if ($faqGroupCollection->getSize()) : ?>
<?php if ($isEnable) : ?>
<div class="faq-collection">
    <?php if ($showGroup) : ?>
        <div class="faq-groups">
            <?php foreach ($faqGroupCollection as $group) : ?>
                <div class="faq-group">
                    <a href="#group<?php /* @noEscape */ echo $group->getFaqgroupId(); ?>" class="group-link">
                        <div class="faq-group-image">
                        <?php if ($group->getIcon()) : ?>
                            <img class="group-image"
                                 src="<?php /* @noEscape */ echo $block->getImageUrl($group->getIcon()); ?>" />
                        <?php else : ?>
                            <img class="group-image" 
                                 src="<?php /* @noEscape */ echo $block->getViewFileUrl('Prince_Faq::images/faq.png'); ?>" />
                        <?php endif; ?>
                        </div>
                    </a>
                    <div class="faq-groupname">
                    <a href="#group<?php /* @noEscape */ echo $group->getFaqgroupId(); ?>" class="group-link">
                        <?php /* @noEscape */ echo $group->getGroupName(); ?>
                    </a>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>
    <div class="faq-content">
        <?php foreach ($faqGroupCollection as $group) : ?>
            <?php if ($showGroupTitle) : ?>
                <div class="group-title" id="group<?php /* @noEscape */ echo $group->getFaqgroupId(); ?>">
                    <i></i><?php /* @noEscape */ echo $group->getGroupName(); ?>
                </div>
            <?php endif; ?>
            <div class="faq-accordion">
            <?php $faqCollection = $block->getFaqCollection($group->getId()); ?>
                <?php if ($faqCollection->getSize()) : ?>
                    <?php foreach ($faqCollection as $faq) : ?> 
                        <h3><?php /* @noEscape */ echo $faq->getTitle(); ?></h3>
                        <div>
                            <p><?php /* @noEscape */ echo $block->filterOutputHtml($faq->getContent()); ?></p>
                        </div>
                    <?php endforeach; ?>
                <?php else : ?>
                    <div><?php /* @noEscape */ echo __('No FAQ available'); ?></div>
                <?php endif; ?>
            </div>
        <?php endforeach; ?>
    </div>
</div>
<?php endif; ?>
<?php else : ?>
<div>
    <h1><?php /* @noEscape */ echo __('No FAQ Group available'); ?></h1>
</div>
<?php endif; ?>

In this file, I just rearranged a few containers so the entire group image can be selected instead of just a small portion of it.

mageprince commented 6 years ago

Hi, @trucatchtraps Thanks for your improvement. I will add your improvement in next version of the module.