Styling block with setBlockWrapperStart does not work + date 1970?

Permalink
Hi,

I want to hide a block if empty and show if there is something so I have the following code and it works but it does not get styled with the class I have given the div .xxxxx. it also does nto show the text behind the div "tatatat" I put it there to test if the code worked.

What did I do wrong?

<?php  
            $pageBlocks = $c->        
           getBlocks('Extra Content');
            $hasStuff = false;
            foreach ($pageBlocks as $pb) {
            if ($pb->btHandle != NULL) {$hasStuff = true;}
            break;
            }
            if ($hasStuff || $c->isEditMode()) {
        ?>
      <?php
         $a->setBlockWrapperStart('<div class="xxxxx" style="color:red;">tatatat');
         $a->setBlockWrapperEnd('</div>');
         $a= new Area ('Extra Content');
         $a->display($c);

 
enlil replied on at Permalink Reply
enlil
whack my previous response... here is a working snip...

<?php  
         $a = new MagicArea('Main'); 
         $a->setBlockWrapperStart('<div class="my-class">');
         $a->setBlockWrapperEnd('</div>');
         $a->display($c); 
      ?>
enlil replied on at Permalink Reply
enlil
"MagicArea" is for magic data integration, just use "Area" :)

Looks like in your code your not defining $a until after you've tried to apply the wrapper...
mesign replied on at Permalink Reply
Thanks for your fast reply! I Can test it the day after tommrow so I will let u know then.
mesign replied on at Permalink Reply
Hey, I tried you code and when there is content it is visible and styled.

But when the block is empty it also takes the style (padding).
So it does not work...

Example:
http://bit.ly/1crRNZE
has text below photo so gets styled (padding, etc.)

http://bit.ly/174DudJ
Has no text below photo... stil gets the style from:
<?php  
            $pageBlocks = $c->        
           getBlocks('Extra Content');
            $hasStuff = false;
            foreach ($pageBlocks as $pb) {
            if ($pb->btHandle != NULL) {$hasStuff = true;}
            break;
            }
            if ($hasStuff || $c->isEditMode()) {
        ?>
      <?php
         $a= new Area ('Extra Content');
         $a->setBlockWrapperStart('<div class="mainitemfull">');
         $a->setBlockWrapperEnd('</div>');
         $a->display($c);




Second different problem:

When selecting the publishing date in composer I get 1-1-1970 as year...
(I click to set a date for example 2013-11-14, when selected it shows jj-11-14. If i type 2013 manually it works.)

Any idea howto fix this?
enlil replied on at Permalink Best Answer Reply
enlil
Try something like this to set different classes... Haven't tried this but it should at least give you the right idea...

<?php
     $pageBlocks = $c->getBlocks('Extra Content');
     $hasStuff = false;
          foreach ($pageBlocks as $pb) {
               if ($pb->btHandle != NULL) {$hasStuff = true;}
               break;
          }
     if ($hasStuff || $c->isEditMode()) {
          $a= new Area ('Extra Content');
          $a->setBlockWrapperStart('<div class="mainitemfull">');
          $a->setBlockWrapperEnd('</div>');
          $a->display($c);
     } else {
         $a= new Area ('Extra Content');
         $a->setBlockWrapperStart('<div class="mainitemfull2">');
mesign replied on at Permalink Reply
Super it works!
Only one thing...

<?php
          $pageBlocks = $c->getBlocks('content1');
          $hasStuff = false;
              foreach ($pageBlocks as $pb) {
                  if ($pb->btHandle != NULL) {$hasStuff = true;}
                  break;
              }
          if ($hasStuff || $c->isEditMode()) {
              $a= new Area ('content1');
              $a->setBlockWrapperStart('<div class="content">');
              $a->setBlockWrapperEnd('</div>');
              $a->display($c);
          } else {
             $a= new Area ('content1');
             $a->setBlockWrapperStart('<!--<div class="content">');

If there is nothing I put the <!-- --> code in. That is fine but it also does that if I work in edit mode.

I thought "if ($hasStuff || $c->isEditMode()) {" means if it has some data or is in editmode then apply the following code "...code..."
I also tried to replace it with &&, tried elseif statement and tested with inline css to be sure, but it all failed..

Thank you for your help