RSS   Twitter   Copiny   Copiny
Нашел ошибку? 

Выдели фрагмент текста с ошибкой или неточностью и нажми Ctrl+Enter!

Создание своего стиля сhrome для модулей

Chrome - это конечная обработка html-кода модуля перед его вставкой в главный шаблон сайта. Существуют несколько предопределенных Chrome-стилей (table, horz, xhtml, rounded, outline), но не всегда то что есть подходит для решения текущих задач.

Чтобы определить собственный стиль отображения в шаблоне, нужно создать файл "modules.php" в директории "html". То есть для шаблона с именем "my_template" файл должен располагаться тут - "templates/my_template/html/modules.php".

В этом файле вы должны определить функцию с названием "modChrome_STYLE" где STYLE это имя вашего стиля. Эта функция будет принимать три аргумента - $module, &$params и &$attribs как показано ниже:

function modChrome_STYLE ( $module, &$params, &$attribs )
{
     /* обработка и вывод html-кода модуля */ 
}

В этой функции вы можете использовать любой PHP-код, а так же вам будут доступны все параметры самого модуля, его свойства и любые данные сохраненные в базе данных Joomla. В основном бывают нужны только следующее

  • $module->content - контент самого модуля, непосредственный html-код.
  • $module->title - название модуля, указанное в панели управления в менеджере модулей.
  • $module->showtitle - флаг, показывать название или нет (true или false).

Функция modChrome_STYLE - это обыкновенная php-функция, здесь можете использовать абсолютно любой php-код. Ниже приведен пример, если в настройках модуля включено отображение заголовка, то выведется текст заголовка перед контентом модуля.

function modChrome_STYLE ( $module, &$params, &$attribs )
{
    if ($module->showtitle) {
        echo '<h2>' .$module->title .'</h2>'; 
    }
    echo $module->content;
}

Есть возможность обратиться к любым параметрам модуля. Например, обрамим модуль классом

<div class="<?php echo $params->get( 'moduleclass_sfx' ); ?>">
    <!-- div contents -->
</div>

Так же можно в код позиции добавлять свои атрибуты, которые используются в Chrome. Для этого в тег позиции <jdoc:include /> добавьте собственные атрибуты. Имена дополнительных атрибутов можно указывать произвольные, они все будут передаваться в ассоциативный массив $attribs.

Практический пример Chrome-функции:

function modChrome_custom( $module, $params, $attribs ) {
    if (isset( $attribs['headerLevel'] )) 
    {
        $headerLevel = $attribs['headerLevel'];
    } else {
        $headerLevel = 3;
    }

    if (isset( $attribs['background'] )) 
    {
        $background = $attribs['background'];
    } else {
        $background = 'blue';
    }
 
    echo '<div >';

    if ($module->showtitle) 
    {
        echo '<h' .$headerLevel .'>' .$module->title .'</h' .$headerLevel .'>';
    }
 
    echo '<div class='.$background.'>';
    echo $module->content;
    echo '</div>';
 
    echo '</div>';
}

Практические примеры использования функции "modChrome_custom"

<!-- вызов в шаблоне -->
<jdoc:include type="modules" name="user1" style="custom" />

<!-- HTML-код на выходе -->
<div>
    <h3><!-- Module title --></h3>
    <div class="blue">
        <!-- Module content -->
    </div>
</div>
<!-- вызов в шаблоне -->
<jdoc:include type="modules" name="user1" style="custom" background="green" />

<!-- HTML-код на выходе -->
<div>
    <h3><!-- Module title --></h3>
    <div class="green">
        <!-- Module content -->
    </div>
</div>
<!-- вызов  в шаблоне -->
<jdoc:include type="modules" name="user1" style="custom" headerLevel="1" background="yellow" />

<!-- HTML-код на выходе -->
<div>
    <h1><!-- Module title --></h1>
    <div class="yellow">
        <!-- Module content -->
    </div>
</div>

Смотрите также:
Комментарии (45) Добавить комментарий
  • Anatol
    Anatol
    16 Февраля 2013, 16:41
     ↑  +3  ↓     ответ

    Спасибо за хороший материал.

  • Ирина
    Ирина
    12 Августа 2013, 20:14
     ↑  0  ↓     ответ

    Спасибо, все подробно написано

  • http://tinyurl.com/quest-bars-cheap-44820
    http://tinyurl.com/quest-bars-cheap-44820
    24 Ноября 2019, 06:38
     ↑  0  ↓     ответ

    Hey there! Do you know if they make any plugins to protect against hackers?

    I'm kinda paranoid about losing everything I've

    worked hard on. Any tips?

  • tinyurl.com
    tinyurl.com
    24 Ноября 2019, 23:22
     ↑  0  ↓     ответ

    Hi there! I understand this is sort of off-topic but

    I needed to ask. Does operating a well-established website such as yours

    require a lot of work? I'm brand new to operating

    a blog however I do write in my diary on a daily basis. I'd like to

    start a blog so I can share my experience and views online.

    Please let me know if you have any kind of ideas or tips for

    brand new aspiring blog owners. Appreciate it!

  • coconut oil our
    coconut oil our
    25 Ноября 2019, 20:30
     ↑  0  ↓     ответ

    It's very straightforward to find out any matter on web

    as compared to books, as I found this piece of writing at this web site.

  • ps4 games
    ps4 games
    28 Ноября 2019, 19:27
     ↑  0  ↓     ответ

    Appreciate this post. Will try it out.

  • ps4 games
    ps4 games
    29 Ноября 2019, 10:33
     ↑  0  ↓     ответ

    Does your blog have a contact page? I'm having a tough time locating it but, I'd like to send you an e-mail.

    I've got some creative ideas for your blog you might be interested in hearing.

    Either way, great website and I look forward to seeing it develop over time.

  • ps4 games
    ps4 games
    30 Ноября 2019, 17:07
     ↑  0  ↓     ответ

    I'm really enjoying the design and layout of your blog. It's a very easy on the eyes which makes it much more pleasant for me to come

    here and visit more often. Did you hire out a designer to create your theme?

    Fantastic work!

  • quest bars cheap coupon twitter
    quest bars cheap coupon twitter
    03 Декабря 2019, 08:30
     ↑  0  ↓     ответ

    Hi there, just became alert to your blog through Google, and found

    that it is truly informative. I am gonna watch out for brussels.

    I'll appreciate if you continue this in future.

    A lot of people will be benefited from your writing.

    Cheers!

  • quest bars cheap coupon twitter
    quest bars cheap coupon twitter
    04 Декабря 2019, 03:38
     ↑  0  ↓     ответ

    An outstanding share! I have just forwarded this onto a colleague who has been conducting a little research on this.

    And he in fact ordered me lunch because I found it

    for him... lol. So let me reword this....

    Thanks for the meal!! But yeah, thanks for spending time

    to discuss this topic here on your site.

  • quest bars cheap
    quest bars cheap
    04 Декабря 2019, 10:26
     ↑  0  ↓     ответ

    What's up mates, fastidious piece of writing and good arguments commented at

    this place, I am really enjoying by these.

  • ps4 games
    ps4 games
    05 Декабря 2019, 03:53
     ↑  0  ↓     ответ

    Do you mind if I quote a couple of your articles as long as I provide credit and sources back

    to your webpage? My blog site is in the very same area of interest as yours and my visitors would truly benefit from some of the information you present here.

    Please let me know if this okay with you. Appreciate it!

  • ps4 games
    ps4 games
    06 Декабря 2019, 03:20
     ↑  0  ↓     ответ

    Hello to all, how is everything, I think every one is getting more from this web site,

    and your views are fastidious designed for new people.

  • ps4 games
    ps4 games
    06 Декабря 2019, 10:40
     ↑  0  ↓     ответ

    Excellent beat ! I would like to apprentice at the same time as you amend your site, how can i subscribe for

    a weblog web site? The account aided me a appropriate deal.

    I had been tiny bit familiar of this your broadcast offered bright clear idea

  • ps4 games
    ps4 games
    06 Декабря 2019, 16:35
     ↑  0  ↓     ответ

    Everything is very open with a really clear clarification of the issues.

    It was truly informative. Your site is extremely helpful.

    Thank you for sharing!

  • ps4 games
    ps4 games
    07 Декабря 2019, 13:04
     ↑  0  ↓     ответ

    Greetings! Very helpful advice in this particular article!

    It's the little changes that make the most important changes.

    Thanks for sharing!

  • quest bars cheap
    quest bars cheap
    07 Декабря 2019, 21:01
     ↑  0  ↓     ответ

    Hello, just wanted to mention, I loved this blog post.

    It was inspiring. Keep on posting!

  • quest bars cheap
    quest bars cheap
    09 Декабря 2019, 23:26
     ↑  0  ↓     ответ

    That is a really good tip especially to those new to the blogosphere.

    Short but very accurate information… Appreciate your sharing this one.

    A must read post!

  • quest bars cheap
    quest bars cheap
    10 Декабря 2019, 14:32
     ↑  0  ↓     ответ

    Excellent goods from you, man. I've understand your stuff previous to

    and you are just extremely excellent. I really like what you've acquired here, really

    like what you're saying and the way in which you say it.

    You make it entertaining and you still care for

    to keep it wise. I can not wait to read much more

    from you. This is really a tremendous website.

  • ps4 games
    ps4 games
    11 Декабря 2019, 01:51
     ↑  0  ↓     ответ

    Great delivery. Great arguments. Keep up the good effort.

  • ps4 games
    ps4 games
    11 Декабря 2019, 23:33
     ↑  0  ↓     ответ

    It's impressive that you are getting ideas from this article as well as from our

    discussion made at this time.

  • ps4 games
    ps4 games
    12 Декабря 2019, 03:49
     ↑  0  ↓     ответ

    We are a group of volunteers and starting a new scheme in our community.

    Your website provided us with valuable information to work on.

    You have done an impressive job and our whole community

    will be thankful to you.

  • ps4 games
    ps4 games
    13 Декабря 2019, 09:16
     ↑  0  ↓     ответ

    It is not my first time to pay a quick visit this site,

    i am visiting this site dailly and get nice data from here daily.

  • coconut oil
    coconut oil
    16 Декабря 2019, 12:20
     ↑  0  ↓     ответ

    Have you ever thought about adding a little bit more than just your articles?

    I mean, what you say is important and all.

    Nevertheless just imagine if you added some great photos or videos to give your posts

    more, "pop"! Your content is excellent but with pics and videos, this website could certainly be one of the

    best in its niche. Great blog!

  • coconut oil
    coconut oil
    18 Декабря 2019, 01:55
     ↑  0  ↓     ответ

    fantastic points altogether, you just won a new

    reader. What may you recommend in regards to your publish that you just made a

    few days in the past? Any positive?

  • coconut oil
    coconut oil
    20 Декабря 2019, 09:14
     ↑  0  ↓     ответ

    Incredible points. Great arguments. Keep up the great effort.

  • plenty of fish vs match.com free trial
    plenty of fish vs match.com free trial
    30 Декабря 2019, 17:59
     ↑  0  ↓     ответ

    I know this if off topic but I'm looking into starting my own blog and was curious what all is

    required to get set up? I'm assuming having a blog

    like yours would cost a pretty penny? I'm not very internet savvy so I'm not 100%

    certain. Any tips or advice would be greatly appreciated. Appreciate it

  • match.com free trial
    match.com free trial
    31 Декабря 2019, 07:25
     ↑  0  ↓     ответ

    This is a topic that's close to my heart...

    Take care! Exactly where are your contact

    details though?

  • https://asksylphoflight.tumblr.com
    https://asksylphoflight.tumblr.com
    31 Декабря 2019, 21:40
     ↑  0  ↓     ответ

    It's very trouble-free to find out any matter on net as compared to textbooks, as I found this article at this site.

  • free trial match.com
    free trial match.com
    01 Января 2020, 11:29
     ↑  0  ↓     ответ

    Hello, I desire to subscribe for this weblog to get most recent

    updates, so where can i do it please help

    out.

  • sling tv
    sling tv
    01 Января 2020, 18:17
     ↑  0  ↓     ответ

    Hey There. I found your blog using msn. This is a really

    well written article. I will be sure to bookmark it and return to read more of your useful info.

    Thanks for the post. I'll definitely return.

  • http://tinyurl.com/sling-tv-58661
    http://tinyurl.com/sling-tv-58661
    02 Января 2020, 20:07
     ↑  0  ↓     ответ

    This is my first time pay a quick visit at here and i am in fact impressed to read

    everthing at one place.

  • sling tv
    sling tv
    03 Января 2020, 07:04
     ↑  0  ↓     ответ

    Wonderful blog! I found it while browsing on Yahoo News. Do you have any tips on how

    to get listed in Yahoo News? I've been trying

    for a while but I never seem to get there! Thanks

  • asksylphoflight sling tv
    asksylphoflight sling tv
    05 Января 2020, 06:19
     ↑  0  ↓     ответ

    Pretty part of content. I simply stumbled upon your site and in accession capital to say that I get in fact

    enjoyed account your weblog posts. Any way I will be subscribing

    to your augment or even I success you get admission to persistently rapidly.

  • sling tv
    sling tv
    07 Января 2020, 13:02
     ↑  0  ↓     ответ

    I believe this is one of the most significant info for me.

    And i'm happy reading your article. But wanna remark on few basic

    issues, The website taste is wonderful, the articles is really excellent : D.

    Excellent job, cheers

  • sling tv
    sling tv
    08 Января 2020, 02:43
     ↑  0  ↓     ответ

    I like what you guys are usually up too. This type of clever work and reporting!

    Keep up the very good works guys I've added you guys to my own blogroll.

  • sling tv
    sling tv
    08 Января 2020, 03:27
     ↑  0  ↓     ответ

    Hello to every , as I am in fact keen of reading this website's post to be updated regularly.

    It includes good information.

  • sling tv
    sling tv
    14 Января 2020, 11:23
     ↑  0  ↓     ответ

    Hey there, You've done a fantastic job. I will certainly digg it and personally recommend to my friends.

    I am confident they will be benefited from this web site.

  • sling tv
    sling tv
    15 Января 2020, 19:33
     ↑  0  ↓     ответ

    We're a group of volunteers and starting a new scheme in our community.

    Your web site provided us with valuable info to work on. You have done an impressive job and our whole community will be grateful

    to you.

  • sling tv
    sling tv
    18 Января 2020, 19:08
     ↑  0  ↓     ответ

    Howdy just wanted to give you a brief heads up and let you know a few of the images aren't loading properly.

    I'm not sure why but I think its a linking issue. I've tried it in two different

    web browsers and both show the same results.

  • sling tv
    sling tv
    19 Января 2020, 09:49
     ↑  0  ↓     ответ

    I have been browsing online more than 3 hours nowadays, yet I

    never found any fascinating article like yours. It's pretty value sufficient for me.

    In my opinion, if all webmasters and bloggers made just right content as

    you did, the internet can be much more useful than ever before.

  • sling tv best package 2020
    sling tv best package 2020
    25 Января 2020, 00:53
     ↑  0  ↓     ответ

    Does your site have a contact page? I'm having trouble locating it but, I'd like to shoot you an email.

    I've got some recommendations for your blog you might

    be interested in hearing. Either way, great blog and I

    look forward to seeing it improve over time.

  • sling tv
    sling tv
    29 Января 2020, 10:59
     ↑  0  ↓     ответ

    I've been browsing online more than 4 hours today, yet I never

    found any interesting article like yours. It's pretty worth enough for me.

    In my view, if all web owners and bloggers made good content as you

    did, the net will be a lot more useful than ever before.

  • cbd oil that works 2020
    cbd oil that works 2020
    04 Апреля 2020, 16:09
     ↑  0  ↓     ответ

    I really like your blog.. very nice colors & theme. Did you make this

    website yourself or did you hire someone to do it for you?

    Plz reply as I'm looking to design my own blog and would like to find out where u got this from.

    many thanks

  • cbd oil that works 2020
    cbd oil that works 2020
    04 Апреля 2020, 19:31
     ↑  0  ↓     ответ

    I'm very happy to find this site. I need to to thank you for ones time due

    to this wonderful read!! I definitely enjoyed

    every bit of it and I have you saved to fav to see new stuff on your site.

Оставить комментарий




* обязательно для заполнения

1 введенный почтовый адрес используется только для обратной связи при ответах в комментариях и сервиса gravatar.com
.