Fork me on GitHub

pnModGetName and left blocks  Bottom

  • OK, I have the following code in my theme that allows me to remove left blocks when launching the forum module"

    Code

    if (pnModGetName() != 'PNphpBB2')
        {

        blocks('left');
        }


    What I'm not sure about is how to add other modules into the selection. I know it should be fairly simple.
  • An easy way to do it would be:

    Code

    if ($GLOBALS['ModName'] == 'ThisModule" || $GLOBALS['ModName'] == 'ThatModule') {
        blocks('
    left');
    }

    The double-pipe indicating "OR"...

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • I tried several variations on that and it didn't work. The closest I got was this:

    Code

    if ($GLOBALS['ModName'] != 'PNphpBB2') {
        blocks('left');
    }

    If I added the pipes and additional item, the first item would quit working. Using your code as is (changing module names), no left blocks showed up.
  • Code

    if ($GLOBALS['ModName'] != 'ThisModule" && $GLOBALS['ModName'] != 'ThatModule') {
        blocks('
    left');
    }


    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • I must be dense because it's still not working. I know I have the module names correct because it works when I do it on individual modules, even with your code but the minute I add multiple modules it either affects every module and removes the left blocks completely or works on none of the modules.
  • Not dense, but perhaps you should consider a PHP primer before proceeding...

    The above code states if the module name *doesn't* equal ThisModule *AND* doesn't equal ThatModule, then show the left blocks.... Perhaps you want to change it to *OR*

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • Tried that actually. I've tried a number of variations and have been using the PHP manual as reference. I've been trying a number of different ways of doing it but can't seem to find one that works when adding multiples. I'll admit, I'm not a very good PHP writer and in fact, couldn't write anything from scratch, but I can usually pick things apart and figure out what they are doing. Just seem to be having problems getting this too work.
  • Well, I did get the following to work, but it seems extremely sloppy. Gotta be a cleaner way of writing it:

    Code

    if (pnModGetName() != 'PNphpBB2')
        {
        if (pnModGetName() != 'My_eGallery')
        {
        if (pnModGetName() != 'My_eReference')
        {
        blocks('left');
        }
        }
    }


    Sorry to be such a pest. I'm going to continue looking at it for a more efficient way of writing it as well.
  • Code

    if ($GLOBALS['ModName'] != 'PNphpBB2' && $GLOBALS['ModName'] != 'My_eGallery' && $GLOBALS['ModName'] != 'My_eReference') {
        blocks('left');
    }

    Will work for *not* showing blocks on either of the above modules, it's pretty simple PHP logic, really...

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • A teeney tiny little sugestion: don't use || or &&. Instead, use | or &. The difference is the single character makes use of a "short-circuited" operator. With &, as soon as you get a false, it stops evaluating the expression and returns false. With |, a true value makes it immediately evaluate to true. This can save evaluating the second operator, which is a bit more efficient. However, if you have values that change during evaluation (for instance, an i++ type expression) short-circuiting could be veeeery dangerous. Would it evaluate and change the value? Beats me. I'm guessing it might not.

    At any rate, I'm a fan of the short circuit. Give it a try.

    Frank
  • I'm going to try that as I haven't been able to get the above code to work.
  • 0 users

This list is based on users active over the last 60 minutes.