Can the Joomla module “know” what position it is in? (2)

This is my first question on StackOverflow. I tried to post a comment in a message Can the Joomla module “know”? what position is he in? but could not find any way to do this, so I have to ask one more question here. Any advice on how to do this properly is very welcome. Anyway, here are my questions:

I tried the code mentioned in the above post, but it didn't seem to work. I'm not only new to PHP, but also coding, so I'm not sure if it is me or the code. Here is what I did with the default.php file:

1) so that I paste the code in the right place, I insert

<?php echo(print_r($module)); ?> 

and he outputs 1 in the correct position;

2) the position name that I need to determine is "showcase-a", so I am inserting the code

  <?php if ($module->position == 'showcase-a'):?>test<?php endif;?> 

to the indicated location, but this time he does not show anything;

3), I tried this code:

  <?php if ($module):?><span>test</span><?php endif; ?> 

But still he does not display the “test” in the position, as I expected.

4) I tried

  <?php if (1):?><span>test</span><?php endif; ?> 

and the test "test" is displayed as good. Therefore, I did not formulate the IF statement incorrectly.

Now I am completely lost. Since print_r ($ module) outputs 1, the $ module must be positive, why does PHP ignore the test in 3)? This is just a side issue for learning PHP. What I still need to decide is to let the module determine what position it is in. Please help. Thanks!

+4
source share
2 answers

I'm not sure that I use it in the template (although this is not the case at all), but my modules often access this position:

 $module->position 

in the module (so mod_something.php), so try putting it there if it is available, just set the variable and it will also be available in the view.

+1
source

If the function $ module-> does not work for you. The $ module-> position can only work for joomla 1.7, 2.5 and +, but I'm not sure. $ module-> works in joomla 2.5.

Otherwise, you need to make the module.php function

Check file

/templates/you-template/html/modules.php

For example, you make your position next in your template (e.g. index.php)

 <jdoc:include type="modules" name="header" style="includeposition" /> 

inside / templates / you -template / html / modules.php

You create a function like this:

 <?php function modChrome_includeposition($module, &$params, &$attribs){ //Set a value to $module->position $module->position='WHATEVER YOUWANT'; ?> <div class="moduletable <?php echo $params->get('moduleclass_sfx').' '.$module->name; ?>"> <?php if($module->showtitle){ ?> <div class="modtitle"> <div class="fleche"> <span> <?php echo $module->title; ?> </span> </div> </div> <?php } ?> <div class="modcontent"> <?php echo $module->content; ?> <div class="clear"> </div> </div> </div> <?php } ?> 

Create names of various functions that, if necessary, set different values.

the name of the function will correspond to the setting you set:

 modChrome_includeposition($module, &$params, &$attribs) 

because

 style="includeposition" 

inside your jdoc.

+1
source

All Articles