web-dev-qa-db-fra.com

Comment puis-je ajouter une classe à chaque module produit?

Je veux créer mon propre modèle et je veux qu'il soit basé sur Bootstrap 4 (mais je pourrais changer à l'avenir).

Je peux créer mes positions de module, mais comment puis-je affecter une classe à chaque module, c'est-à-dire class="col"

1
Eoin

index.php

// Count the modules
$belowBanner = ($this->countModules('belowBanner'));
...
// if the position below module has modules then output code
        <?php if ($belowBanner) : ?>
// my container div gives the width.  Bootstrap requires a div with the class row for each row.  I also add a section.
            <div class="container">
                <div class="row">
                    <section id="<?php echo "belowBanner" ?>">
// insert a module position.  The type is always modules.  Give it a unique name "belowBanner" and give it the default module chrome of "bootstrap4"
                        <jdoc:include type="modules" name="belowBanner" style="bootstrap4" />
                    </section>
                </div>
            </div>
        <?php endif ?>

module.php qui se trouve dans le dossier/html /

    <?php
    /**
     * @package     Joomla.Administrator
     * @subpackage  Templates.joomla-london
     *
     * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
     * @license     GNU General Public License version 2 or later; see LICENSE.txt
     */
    defined('_JEXEC') or die;
    /**
     * This is a file to add template specific chrome to module rendering.  To use it you would
     * set the style attribute for the given module(s) include in your template to use the style
     * for each given modChrome function.
     *
     * This gives template designers ultimate control over how modules are rendered.
     *
     * NOTICE: All chrome wrapping methods should be named: modChrome_{STYLE} and take the same
     * two arguments.
     */
    /*
     * Module chrome for rendering the module in a belowBanner
     */

    // make sure you name it correctly.  it always starts modChrome and I have named it bootstrap4 as I will be using that framework.  I could have called it anything, but I thought this was the most meaningful/descriptive name.
    function modChrome_bootstrap4($module, &$params, &$attribs)
    {
    // if the module has content
        if ($module->content)
        {
            // Get module params
    // get Bootstrap size and make sure it is returned as an integer
            $bootstrapSize = (int) $params->get('bootstrap_size');
    // if nothing has been selected then just use the class cols
$cols = "col";

    // if the bootstrap class is anything except 0 then insert the class cols- and add the bootstrap size class
            if ($bootstrapSize != '0') {
 $cols = "col-" . $bootstrapSize;}


    // If the modules title is set to show... then show it
            if ($module->showtitle)
            {
                echo '<h2>' .$module->title .'</h2>';
            }
        ?>
    // output a div and add the column class to it.  It will either be col or col-x depending on the bootstrap size.  So perhaps col-6 or col-4
        <div class="items<?php echo " ". $cols;?> ">
            <div class="item">
    // output the module content
                <?php echo $module->content; ?>

            </div>
        </div>

    <?php
        }
    }
    ?>
0
Eoin