Joomla! Discussion Forums



It is currently Wed Nov 25, 2009 6:47 pm (All times are UTC )

 





Post new topic Reply to topic  [ 25 posts ] 
Author Message
Posted: Tue Aug 14, 2007 3:26 pm 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Mon Sep 12, 2005 7:41 pm
Posts: 1374
Location: Glasgow - Scotland
Hi Guys,

I was chatting with Johan late last night regarding a templating problem I was having, he mentioned to me that the following code:

Code:
$total = $this->countModules('user1 + user2 + user3 + user4');


Should give me the total number of modules published in user1, user2, user3 & user4 - however it doesn't, the value returned is always "1" unless there are no modules published in any of those positions in which case it returns "0".

I tested this on the latest SVN version (8399)

Waseem

_________________
http://www.bulletprooftemplates.com/ - New Joomla 1.5 templates from an old Joomla head
If you don't know the answer don't be afraid to ask someone who does


Last edited by Jinx on Sun Aug 19, 2007 6:10 am, edited 1 time in total.

Top
  E-mail  
 
Posted: Tue Aug 14, 2007 3:44 pm 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Wed Oct 05, 2005 7:25 am
Posts: 1012
Location: Amsterdam
Waseem I had the same conversation with Jinx some time ago and I tried to convince him that it did not work.
But now it seems that you are having the same problem.
I solved by splittiing it up like this:
Quote:
$total = $this->countModules('user1')  + $this->countModules('user2')  + $this->countModules('user3')  + $this->countModules('user4');

_________________
Joomla Bug Squad

Note: Sending me private messages for personal support, without this been requested, would lead to ignoring any of your posts in future!


Top
   
 
Posted: Tue Aug 14, 2007 6:20 pm 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Mon Sep 12, 2005 7:41 pm
Posts: 1374
Location: Glasgow - Scotland
Thanks Pieter,

I actually ended up with similar code, what I need to do is find out how many of the positions user1, user2, user3, and user4 have modules published in them rather than how many modules are published.

This is what I did:

Code:
/* check which module areas have published modules */
if ($this->countModules('user1')) $user1 = "1";
if ($this->countModules('user2')) $user2 = "1";
if ($this->countModules('user3')) $user3 = "1";
if ($this->countModules('user4')) $user4 = "1";

/* output the total */
$total = ($user1 + $user2 + $user3 + $user4);


Waseem

_________________
http://www.bulletprooftemplates.com/ - New Joomla 1.5 templates from an old Joomla head
If you don't know the answer don't be afraid to ask someone who does


Top
  E-mail  
 
Posted: Wed Aug 15, 2007 10:56 am 
User avatar
Joomla! Champion
Joomla! Champion
Offline

Joined: Fri Aug 12, 2005 12:47 am
Posts: 6431
It looks like the countModules code has been changed from the one I originaly put in. I have changed it back to the original code and it should now be working again as expected. Changes will be in SVN when I get back home in 24 hours.

_________________
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.nooku.org - multi-lingual content manager and rapid extension development framework for Joomla 1.5
http://www.joomlatools.eu - training, consulting and extension development


Top
   
 
Posted: Wed Aug 15, 2007 12:10 pm 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Mon Sep 12, 2005 7:41 pm
Posts: 1374
Location: Glasgow - Scotland
  :D

Thanks Johan!

_________________
http://www.bulletprooftemplates.com/ - New Joomla 1.5 templates from an old Joomla head
If you don't know the answer don't be afraid to ask someone who does


Top
  E-mail  
 
Posted: Wed Aug 15, 2007 3:16 pm 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Wed Oct 05, 2005 7:25 am
Posts: 1012
Location: Amsterdam
Jinx wrote:
It looks like the countModules code has been changed from the one I originaly put in. I have changed it back to the original code and it should now be working again as expected. Changes will be in SVN when I get back home in 24 hours.


I will do some testing of course, Johan :)

_________________
Joomla Bug Squad

Note: Sending me private messages for personal support, without this been requested, would lead to ignoring any of your posts in future!


Top
   
 
Posted: Wed Aug 15, 2007 9:11 pm 
User avatar
Joomla! Champion
Joomla! Champion
Offline

Joined: Fri Aug 12, 2005 12:47 am
Posts: 6431
Code has been committed, found internet access on the airport. Check it out and let me know it works. It should ;)

_________________
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.nooku.org - multi-lingual content manager and rapid extension development framework for Joomla 1.5
http://www.joomlatools.eu - training, consulting and extension development


Top
   
 
Posted: Thu Aug 16, 2007 8:41 am 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Mon Sep 12, 2005 7:41 pm
Posts: 1374
Location: Glasgow - Scotland
Confirmed :)

The code you mentioned does indeed work Johan - only problem I've got is that if I have 2 modules published in user1 and one published in user2 it's gonna return 3 (and rightly so), not the result I'm looking for though lol. I need it to return 2.

My fudged code works a treat for what i need but glad you got this one fixed

Waseem

_________________
http://www.bulletprooftemplates.com/ - New Joomla 1.5 templates from an old Joomla head
If you don't know the answer don't be afraid to ask someone who does


Top
  E-mail  
 
Posted: Thu Aug 16, 2007 11:00 am 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Wed Oct 05, 2005 7:25 am
Posts: 1012
Location: Amsterdam
I did a quick test last night (midnight) but it did not do what I was expecting.
May be I was a little sleepy! I will have another look but if it worked for waseem, it must be okay.

_________________
Joomla Bug Squad

Note: Sending me private messages for personal support, without this been requested, would lead to ignoring any of your posts in future!


Top
   
 
Posted: Thu Aug 16, 2007 9:08 pm 
User avatar
Joomla! Champion
Joomla! Champion
Offline

Joined: Fri Aug 12, 2005 12:47 am
Posts: 6431
Waseem,

I'm afraid that what you are trying to do is not posisble with one countModules call. Could you explain why you need this functionality ?

Johan

_________________
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.nooku.org - multi-lingual content manager and rapid extension development framework for Joomla 1.5
http://www.joomlatools.eu - training, consulting and extension development


Top
   
 
Posted: Fri Aug 17, 2007 10:55 am 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Mon Sep 12, 2005 7:41 pm
Posts: 1374
Location: Glasgow - Scotland
Hi Johan,

The reason that I need this functionality is actually very simple :)

Say for example I have four "teaser" blocks in a row in my template, I might want to publish two modules in the first teaser block and one in each of two of the remaining three blocks - that adds up to 4 modules and 3 teaser blocks

Here's what I need to do:

1. If all four teaser blocks have modules published in them then the width of each of these teaser blocks must be 25% (100/4)
2. If three of the teaser blocks have modules published in them (regardless of how many modules in each block) then the width of each block must be 33% (100/3), the same goes for 2 teaser blocks and one teaser block (50% and 100% respectively)
3. Using the this->countModules function I can determine how many MODULES I have published but crucially I cannot work out how many module POSITIONS have modules published within them.

ie. given then above scenario the this->countModules function will return "4" the number of modules published, whereas I actually need to return "3" the number of module positions with modules published in them.


Hope this makes sense :)

Waseem

_________________
http://www.bulletprooftemplates.com/ - New Joomla 1.5 templates from an old Joomla head
If you don't know the answer don't be afraid to ask someone who does


Top
  E-mail  
 
Posted: Fri Aug 17, 2007 11:47 am 
User avatar
Joomla! Champion
Joomla! Champion
Offline

Joined: Fri Aug 12, 2005 12:47 am
Posts: 6431
Hi Waseem,

What about using one module position and doing a count on the modules that are published in that position, instead of using different positions ? Wouldn't that solve your problem ?

Johan

_________________
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.nooku.org - multi-lingual content manager and rapid extension development framework for Joomla 1.5
http://www.joomlatools.eu - training, consulting and extension development


Top
   
 
Posted: Fri Aug 17, 2007 12:08 pm 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Mon Sep 12, 2005 7:41 pm
Posts: 1374
Location: Glasgow - Scotland
U got me thinking there.....

I need to take heed of the comment you made the other day about looking at Joomla 1.5 templating from a different angle than Joomla 1.0.x templating ;)

let me try something out and come back to you

Waseem

_________________
http://www.bulletprooftemplates.com/ - New Joomla 1.5 templates from an old Joomla head
If you don't know the answer don't be afraid to ask someone who does


Top
  E-mail  
 
Posted: Fri Aug 17, 2007 1:42 pm 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Mon Sep 12, 2005 7:41 pm
Posts: 1374
Location: Glasgow - Scotland
Hi Johan,

I tried what you suggested and it does indeed work - to an extent. Admittedly it meant I had to rethink my markup and use of css but I have it working now.

It still leaves me with the orignal problem though - in some circumstances I need to be able to count module positions with modules published rather than the number of modules published.

Figure1. thiscountmodules-jinx.png
Shows how the this->countmodules count can be used to work out the width of each module when all are published in one module position.

One needs to add this code to the head of the template's index.php file:
Code:
<?php $total = $this->countModules('user1'); // replace user1 with module name to taste ?>


Then mark up the xhtml like this:
Code:
<?php if ($this->countModules('user1')) : ?>
   <div id="top-user-modules" class="clearfix">
      <div class="inside">
         <div id="user1" class="count<?php echo $total ;?>">
               <jdoc:include type="modules" name="user1" style="xhtml" />
         </div><!-- end user1 -->
      </div><!-- end inside -->                  
         </div><!-- end top-user-modules -->
<?php endif; ?>


and the CSS like this:
Code:
/* -- Teaser Modules -- */
div#top-user-modules {
width:600px; /* or some other width to your liking */
}
div#top-user-modules div.inside {
margin:0px;
padding:10px; /* or other padding to your liking */
}
div.count1 div.moduletable, div.count1 div.module {
width:100%;
float:left;
}
div.count2 div.moduletable, div.count2 div.module {
width:50%;
float:left;
}
div.count3 div.moduletable, div.count3 div.module  {
width:33%;
float:left;
}
div.count4 div.moduletable, div.count4 div.module  {
width:25%;
float:left;
}
div.count5 div.moduletable, div.count5 div.module  {
width:20%;
float:left;
}
div.count6 div.moduletable, div.count6 div.module  {
width:16%;
float:left;
}


Whereas,

Figure2. thiscountmodules-waz.png
Shows the limitations of the this->countmodules when trying to work out the width of each module position, when more than one module is published in on of those positions. As you can see the count is going to be 5 whereas I actually need 4

I have a working model of this second layout, although the CSS/XHTML code is sound (similar to the above) the php code's rather cludgy  :-[

Waseem


You do not have the required permissions to view the files attached to this post.

_________________
http://www.bulletprooftemplates.com/ - New Joomla 1.5 templates from an old Joomla head
If you don't know the answer don't be afraid to ask someone who does


Top
  E-mail  
 
Posted: Fri Aug 17, 2007 5:05 pm 
User avatar
Joomla! Champion
Joomla! Champion
Offline

Joined: Fri Aug 12, 2005 12:47 am
Posts: 6431
Some short initial comments :

1. Why not using an inline css style ?

Instead of doing
Code:
<div id="user1" class="count<?php echo $total ;?>">


You could so :
Code:
<div id="user1" style="width: <?php echo 100/$total ?>%">


This means you can remove all of the extra css.

2. There is no need to make two calls to countModules you can do :

Code:
<?php if ($total = $this->countModules('user1')) : ?>
   <div id="top-user-modules" class="clearfix">
      <div class="inside">
         <div id="user1" class="count<?php echo $total ;?>">
               <jdoc:include type="modules" name="user1" style="xhtml" />
         </div><!-- end user1 -->
      </div><!-- end inside -->                  
         </div><!-- end top-user-modules -->
<?php endif; ?>


This spares you an extra call and makes the code more readable.

3. Instead of doing all this wrapping in your template you could write a special chrome function that wraps your module and does the hard work for you, example :

Code:
<?php if ($this->countModules('user1')) : ?>
   <jdoc:include type="modules" name="user1" style="xhtm mystyle" count="<?php echo $total ?>" id="user1">/>
<?php endif; ?>


You will now need to create a custom modules.php file, add it to your termplate/html folder (see also the system template). The file will need to contain the following function :

Code:
function modChrome_mystyle($module, &$params, &$attribs)
{ ?>
   if (!empty ($module->content)) : ?>
        <div id="top-user-modules" class="clearfix">
      <div class="inside">
         <div id="<?php echo $attribs['id'] ?>" class="count<?php echo $attribs['count'] ;?>">      
                     <?php echo $module->content; ?>
         </div><!-- end user1 -->
      </div><!-- end inside -->                  
         </div><!-- end top-user-modules -->
        <?php endif;
}


This shows the true power of jdoc:include in action, take special note how the modules count is passed to the chrome function and used to calcumate the width of the module on the fly. This technique keeps you template code very lean and mean and allows you to create re-usable module wrappers.

Hope this helps.

PS. I have not tested the code, it should work though.

Update I  : made small change to the code to make it more flexible.
Update II : changed style="mystyle", to style="xhtml mystyle" to demonstrate cascading effect on module styles

_________________
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.nooku.org - multi-lingual content manager and rapid extension development framework for Joomla 1.5
http://www.joomlatools.eu - training, consulting and extension development


Last edited by Jinx on Mon Aug 20, 2007 8:47 am, edited 1 time in total.

Top
   
 
Posted: Fri Aug 17, 2007 9:58 pm 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Mon Sep 12, 2005 7:41 pm
Posts: 1374
Location: Glasgow - Scotland
what more can I say than wow!! :)

Thanks Johan!

_________________
http://www.bulletprooftemplates.com/ - New Joomla 1.5 templates from an old Joomla head
If you don't know the answer don't be afraid to ask someone who does


Top
  E-mail  
 
Posted: Sun Aug 19, 2007 1:12 pm 
User avatar
Joomla! Ace
Joomla! Ace
Online

Joined: Fri Aug 26, 2005 1:31 am
Posts: 1246
That's sneaky, it never occurred to me to put php logic in the chrome....

Isn't that fixed to user1 though? I guess you could take out that id from the chrome...

_________________
Joomlashack - Professional Hand Coded Joomla Templates
www.joomlashack.com/professional-joomla-templates
Fully Managed Joomla Hosting
www.joomlashack.com/joomla-hosting


Top
   
 
Posted: Sun Aug 19, 2007 8:46 pm 
User avatar
Joomla! Champion
Joomla! Champion
Offline

Joined: Fri Aug 12, 2005 12:47 am
Posts: 6431
compass wrote:
That's sneaky, it never occurred to me to put php logic in the chrome....


One man's sneaky is another man's smart. ;)

Quote:
Isn't that fixed to user1 though? I guess you could take out that id from the chrome...


Fixed. Updated code a bit to improve flexibility.

_________________
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.nooku.org - multi-lingual content manager and rapid extension development framework for Joomla 1.5
http://www.joomlatools.eu - training, consulting and extension development


Top
   
 
Posted: Sun Aug 19, 2007 9:10 pm 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Wed Oct 05, 2005 7:25 am
Posts: 1012
Location: Amsterdam
Nice solution, Johan.
But to ask a question: what is the concept of a chrome? To me it is just a bit of (clever, in this case) code.
Why the name: chrome? Or is my english failing me?

_________________
Joomla Bug Squad

Note: Sending me private messages for personal support, without this been requested, would lead to ignoring any of your posts in future!


Top
   
 
Posted: Sun Aug 19, 2007 10:12 pm 
User avatar
Joomla! Champion
Joomla! Champion
Offline

Joined: Fri Aug 12, 2005 12:47 am
Posts: 6431
pvh123 wrote:
But to ask a question: what is the concept of a chrome? To me it is just a bit of (clever, in this case) code.
Why the name: chrome? Or is my english failing me?


The name chrome comes from GUI development, the chrome are the UI elements that are 'wrapped' around a window, for example the title bar, the status bar, ..... The word 'chrome' is used alot in Mozilla development, this is also where we lended the concept.

The concept behind a chrome function is very simple, it allows a template designer to create custom module wrappers 'chrome' as I demonstrated in my example.

By default the system provides the following chrome functions, none, table, horz, xhtml and rounded. These do the same as the old 0, -1, -2, -3 module styles. (You can find them in templates/system/html/modules.php)

This solution is indeed nothing more the a bit of PHP code, hehe, Joomla! is written in PHP afterall right ;) What i think is the beauty of this concept is that it allows you to create your own module wrapper, you can even nest multiple wrappers. This gives the template developer a ton of re-usable flexibility.

It will probbaly take a while before template developers discover the true potential of this feature, but once they do they will see that the possibilities are almost endless. Hehe, I can think of some very nifty stuff I could do with module chrome, AJAX driven drag and droppable modules anyone ? ;)

_________________
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.nooku.org - multi-lingual content manager and rapid extension development framework for Joomla 1.5
http://www.joomlatools.eu - training, consulting and extension development


Last edited by Jinx on Sun Aug 19, 2007 10:14 pm, edited 1 time in total.

Top
   
 
Posted: Sun Aug 19, 2007 11:06 pm 
User avatar
Joomla! Ace
Joomla! Ace
Online

Joined: Fri Aug 26, 2005 1:31 am
Posts: 1246
pvh123 wrote:
Nice solution, Johan.
But to ask a question: what is the concept of a chrome? To me it is just a bit of (clever, in this case) code.
Why the name: chrome? Or is my english failing me?


Chrome was actually in 1.0.

You could select -3 to get div div div. The most common use of this was to get 4 rounded corners (you got a block element for each corner).

1.5 allows you to customize the chrome, to acheive pretty much, as Johan says... anything.

@jinx
"Update II : changed style="mystyle", to style="xhtml,mystyle" to demonstrate cascading effect on module styles"

cascading...? how would that work?

_________________
Joomlashack - Professional Hand Coded Joomla Templates
www.joomlashack.com/professional-joomla-templates
Fully Managed Joomla Hosting
www.joomlashack.com/joomla-hosting


Top
   
 
Posted: Mon Aug 20, 2007 7:53 am 
User avatar
Joomla! Ace
Joomla! Ace
Offline

Joined: Wed Oct 05, 2005 7:25 am
Posts: 1012
Location: Amsterdam
Jinx wrote:

It will probbaly take a while before template developers discover the true potential of this feature, but once they do they will see that the possibilities are almost endless. Hehe, I can think of some very nifty stuff I could do with module chrome, AJAX driven drag and droppable modules anyone ? ;)


Thanks very much, jinx and compass, for the explanation.
@jinx I can see wonderfull things coming on. Only AJAX is this football club in Amsterdam and it always confuses me.

_________________
Joomla Bug Squad

Note: Sending me private messages for personal support, without this been requested, would lead to ignoring any of your posts in future!


Top
   
 
Posted: Wed Aug 29, 2007 4:37 pm 
User avatar
Joomla! Intern
Joomla! Intern
Offline

Joined: Fri Dec 30, 2005 2:32 am
Posts: 54
What is an example of "Joomla 1.5 chrome can accomplish anything"?  You mean not limited to the standard module outputs (i.e. -1, -2, -3,.....xhtml, rounded ,etc.)?

_________________
Rick Blalock
XiD


Top
  E-mail  
 
Posted: Wed Aug 29, 2007 5:02 pm 
User avatar
Joomla! Champion
Joomla! Champion
Offline

Joined: Fri Aug 12, 2005 12:47 am
Posts: 6431
That and more yes, it will be up to your own creativity.

_________________
Johan Janssens - Joomla Co-Founder, Lead Developer of Joomla 1.5

http://www.nooku.org - multi-lingual content manager and rapid extension development framework for Joomla 1.5
http://www.joomlatools.eu - training, consulting and extension development


Top
   
 
Posted: Thu Aug 30, 2007 2:56 am 
User avatar
Joomla! Ace
Joomla! Ace
Online

Joined: Fri Aug 26, 2005 1:31 am
Posts: 1246
rblalock wrote:
What is an example of "Joomla 1.5 chrome can accomplish anything"?  You mean not limited to the standard module outputs (i.e. -1, -2, -3,.....xhtml, rounded ,etc.)?


The easiest way to think of it is that the -1, -2 etc are *examples* of chrome. Ones that are shipped with default Joomla install. You can make you own up to achieve needed effects.

Chrome is the generic name for any kind of module output....

_________________
Joomlashack - Professional Hand Coded Joomla Templates
www.joomlashack.com/professional-joomla-templates
Fully Managed Joomla Hosting
www.joomlashack.com/joomla-hosting


Top
   
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ] 

Quick reply

 



Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group