Jos Posted October 30, 2012 Share Posted October 30, 2012 (edited) Hi, I'm completely new to coding in php. I'm stuck with this: For a Joomla template I need to set up variables, using countModules. This is what I try to do, but I am getting nowhere: I want to create a three column template, based on the Skeleton CSS Framework. <div id="left" class="four columns"> <-- left sidebar <div id="main" class="eight columns"> <-- Joomla component <div id="right class="four columns"> <-- right sidebar That's the basic template, with all three columns present. If one sidebar is missing, then "main" has to change from class="eight columns" into class="twelve columns". If both sidebars are missing, "main" has to change to class="sixteen columns". I understand I have to set up variables first. I give them the value 0. $left = 0, $right = 0, $main = 0 + ($left + $right) Then I would use countmodules to count the modules, to get a value. Being 0 (no modules) or 1 (modules present). If the total = 0, (no sidebars present) $main would be 0, and that should echo "sixteen" columns. If the total is 1, (1 sidebar present) $main would be 1, giving echo "twelve" columns If the total is 2, (2 sidebars present) $main would be 2, giving echo "eight" columns. That's roughly how it should be, I think. But it doesn't work. Can anyone help me to get this working correctly? Thanks, Jos Edited October 30, 2012 by Jos Quote Link to comment Share on other sites More sharing options...
sumpygump Posted October 30, 2012 Share Posted October 30, 2012 Is countModules a Joomla internal function or one you are making? What are the inputs and what is the expected output vs the actual output? You mention that it doesn't work. What exactly isn't working? Quote Link to comment Share on other sites More sharing options...
Jos Posted October 30, 2012 Author Share Posted October 30, 2012 (edited) countModules is a Joomla internal function. I don't know (yet) what an input is. I'm more into templating and general html rather than php, but working on it. Where do I set the variables? In the top of the template, before the variables are called? Or when required, just above the Joomla countmodules? When I echo a variable, to see if it works it echos the value I assigned to it, not what it should be. I set the variables above the code: $left=0 Then the Joomla code: <?php if ($this->countModules ('left')) : ?> <div id="left" class="four columns"> <jdoc:include type="modules" name="left" style="xhtml" /> </div> <?php endif; ?> <?php echo $left; ?> It should give me the value of $left - but it doesn't. It shows me the value I gave it. It should be one (the module is present), it gives me 0. Edited October 30, 2012 by Jos Quote Link to comment Share on other sites More sharing options...
sumpygump Posted October 30, 2012 Share Posted October 30, 2012 (edited) Okay, great! Welcome to the world of coding in PHP. So, by input I mean what do you pass into the function countModules(). The input is the text in between the parentheses, so in your example, it is 'left.' I don't know anything about Joomla, but I read the description of that page about countModules(). It seems like you have three modules which you are trying to use, which are 'left', 'main', and 'right.' Is that correct? I don't think you need to set the variable $left, $right or $main in your code. Instead I think you want to do something like this: <?php if ($this->countModules ('left')) : ?> <div id="left" class="four columns"> <jdoc:include type="modules" name="left" style="xhtml" /> </div> <?php endif; ?> <?php // assumes no sidebars $mainWidth = 'sixteen'; // detect if at least one sidebar if ($this->countModules('left or right')) { $mainWidth = 'twelve'; } // detect if both sidebars present if ($this->countModules('left and right')) { $mainWidth = 'eight'; } ?> <div id="main" class="<?php echo $mainWidth; ?> columns"> <!-- // main content here --> </div> <?php if ($this->countModules ('right')) : ?> <div id="right" class="four columns"> <jdoc:include type="modules" name="right" style="xhtml" /> </div> <?php endif; ?> That might be what you need based on your original description. If you're curious about what the return values of $this->countModules() is, instead of echo $left; try, echo $this->countModules('left'); Edited October 30, 2012 by sumpygump Quote Link to comment Share on other sites More sharing options...
Jos Posted October 30, 2012 Author Share Posted October 30, 2012 Thanks, I'm working my rear end off to get somewhat acquainted with php, this really helps a lot. I'm gonna try it out. If it doesn't work, I'll get back to you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.