Создание своего стиля сhrome для модулей
рейтинг: 8.3/10, голосов: 14
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>
Спасибо за хороший материал.
Спасибо, все подробно написано
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?
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!
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.
Appreciate this post. Will try it out.
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.
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!
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!
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.
What's up mates, fastidious piece of writing and good arguments commented at
this place, I am really enjoying by these.
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!
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.
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
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!
Greetings! Very helpful advice in this particular article!
It's the little changes that make the most important changes.
Thanks for sharing!
Hello, just wanted to mention, I loved this blog post.
It was inspiring. Keep on posting!
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!
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.
Great delivery. Great arguments. Keep up the good effort.
It's impressive that you are getting ideas from this article as well as from our
discussion made at this time.
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.
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.
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!
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?
Incredible points. Great arguments. Keep up the great effort.
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
This is a topic that's close to my heart...
Take care! Exactly where are your contact
details though?
It's very trouble-free to find out any matter on net as compared to textbooks, as I found this article at this site.
Hello, I desire to subscribe for this weblog to get most recent
updates, so where can i do it please help
out.
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.
This is my first time pay a quick visit at here and i am in fact impressed to read
everthing at one place.
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
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.
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
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.
Hello to every , as I am in fact keen of reading this website's post to be updated regularly.
It includes good information.
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.
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.
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.
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.
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.
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.
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
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.