Monster menus blocks renders even if empty

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Monster menus blocks renders even if empty

grahamtk
Hi!
While theming a MM block I meet the obstacle that it is always there, even
though it is empty.

Is this as is, or should it not render if it has no content?
There is no "add content here" link in the picture block, so thats not what
renders here.

Any Idea how I can accomplish the following use case?
I find that this use case shows how useful this behaviour can be:
If sidebar content of right sidebar is present
it is (ofcourse) rendered in the right sidebar of a three column layout.

If no sidebar-content: the sidebar region should be empty
and thus collapse, leaving the layout an appropriate two column layout.



--
View this message in context: http://monster-menus.2910260.n2.nabble.com/Monster-menus-blocks-renders-even-if-empty-tp7572858.html
Sent from the Monster Menus mailing list archive at Nabble.com.

---
You are currently subscribed to monster_menus as: [hidden email].
To unsubscribe click here: http://lists.middlebury.edu/u?id=685503.6b071f880fe6a965a128164e6d09ea81&n=T&l=monster_menus&o=700320
or send a blank email to [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Monster menus blocks renders even if empty

McBride, Ian S.
I got around this with a helper function that loops through the region’s content array to check whether there’s any markup to display.

/**
 * Check to see if a region is occupied.
 *
 * @param $content
 *   The machine name of the region to check.
 * @return int 0 if the region contains content, 1 if it does not.
 */
function middlebury_monster_menus_region_empty($content) {
  if (empty($content))
    return TRUE;

  foreach (array_keys($content) as $key) {
    if (preg_match('/monster_menus_/', $key) !== 0) {
      foreach($content[$key] as $index => $value) {
        if ((is_numeric($index) || $index == '#markup') && !empty($value)) {
          return FALSE;
        }
      }
    }
  }

  return TRUE;
}

Then in page.tpl.php I can do this:

    <?php if (!middlebury_monster_menus_region_empty($page['right'])): ?>
      <aside class="sidebar">
        <?php print render($page['right']); ?>
      </aside>
    <?php endif; ?>

On 4/3/14, 12:05 PM, "grahamtk" <[hidden email]<mailto:[hidden email]>> wrote:

Hi!
While theming a MM block I meet the obstacle that it is always there, even
though it is empty.

Is this as is, or should it not render if it has no content?
There is no "add content here" link in the picture block, so thats not what
renders here.

Any Idea how I can accomplish the following use case?
I find that this use case shows how useful this behaviour can be:
If sidebar content of right sidebar is present
it is (ofcourse) rendered in the right sidebar of a three column layout.

If no sidebar-content: the sidebar region should be empty
and thus collapse, leaving the layout an appropriate two column layout.



--
View this message in context: http://monster-menus.2910260.n2.nabble.com/Monster-menus-blocks-renders-even-if-empty-tp7572858.html
Sent from the Monster Menus mailing list archive at Nabble.com.

---
You are currently subscribed to monster_menus as: [hidden email]<mailto:[hidden email]>.
To unsubscribe click here: http://lists.middlebury.edu/u?id=685439.7e7cbccf9bb225cf8471bffe1cb67503&n=T&l=monster_menus&o=700320
or send a blank email to [hidden email]<mailto:[hidden email]>


---
You are currently subscribed to monster_menus as: [hidden email].
To unsubscribe click here: http://lists.middlebury.edu/u?id=685503.6b071f880fe6a965a128164e6d09ea81&n=T&l=monster_menus&o=700324
or send a blank email to [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Monster menus blocks renders even if empty

grahamtk
This post has NOT been accepted by the mailing list yet.
Thank you!
this worked beautifully!
Now the banner images of the site can be inherited down the pages,
and if the banner image block is empty, a default rotating banner image can show ( implemented differently).
:)

It also let me have the collapsing sidebar and thus custom layout based on content. great!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Monster menus blocks renders even if empty

grahamtk
In reply to this post by McBride, Ian S.
Thank you!
this worked beautifully!
Now the banner images of the site can be inherited down the pages,
and if the banner image block is empty, a default rotating banner image can
show ( implemented differently).
:)

It also let me have the collapsing sidebar and thus custom layout based on
content. great!



--
View this message in context: http://monster-menus.2910260.n2.nabble.com/Monster-menus-blocks-renders-even-if-empty-tp7572859p7572863.html
Sent from the Monster Menus mailing list archive at Nabble.com.

---
You are currently subscribed to monster_menus as: [hidden email].
To unsubscribe click here: http://lists.middlebury.edu/u?id=685503.6b071f880fe6a965a128164e6d09ea81&n=T&l=monster_menus&o=700331
or send a blank email to [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Monster menus blocks renders even if empty

Dan Wilga-2
In reply to this post by grahamtk
We do something similar, by statically examining the nested array with
empty(). Ian's solution is more elegant, though, in that it can be
reused, and isn't as susceptible to minor changes in the array structure.

On 4/3/14, 12:55 PM, McBride, Ian S. wrote:

> I got around this with a helper function that loops through the region’s content array to check whether there’s any markup to display.
>
> /**
>   * Check to see if a region is occupied.
>   *
>   * @param $content
>   *   The machine name of the region to check.
>   * @return int 0 if the region contains content, 1 if it does not.
>   */
> function middlebury_monster_menus_region_empty($content) {
>    if (empty($content))
>      return TRUE;
>
>    foreach (array_keys($content) as $key) {
>      if (preg_match('/monster_menus_/', $key) !== 0) {
>        foreach($content[$key] as $index => $value) {
>          if ((is_numeric($index) || $index == '#markup') && !empty($value)) {
>            return FALSE;
>          }
>        }
>      }
>    }
>
>    return TRUE;
> }
>
> Then in page.tpl.php I can do this:
>
>      <?php if (!middlebury_monster_menus_region_empty($page['right'])): ?>
>        <aside class="sidebar">
>          <?php print render($page['right']); ?>
>        </aside>
>      <?php endif; ?>
>
> On 4/3/14, 12:05 PM, "grahamtk" <[hidden email]<mailto:[hidden email]>> wrote:
>
> Hi!
> While theming a MM block I meet the obstacle that it is always there, even
> though it is empty.
>
> Is this as is, or should it not render if it has no content?
> There is no "add content here" link in the picture block, so thats not what
> renders here.
>
> Any Idea how I can accomplish the following use case?
> I find that this use case shows how useful this behaviour can be:
> If sidebar content of right sidebar is present
> it is (ofcourse) rendered in the right sidebar of a three column layout.
>
> If no sidebar-content: the sidebar region should be empty
> and thus collapse, leaving the layout an appropriate two column layout.

---
You are currently subscribed to monster_menus as: [hidden email].
To unsubscribe click here: http://lists.middlebury.edu/u?id=685503.6b071f880fe6a965a128164e6d09ea81&n=T&l=monster_menus&o=700335
or send a blank email to [hidden email]
Loading...