determine if in edit mode in block template

Permalink 1 user found helpful
i am making a custom block template in which i would like to execute a certain bit of code only if the page is in edit mode. is there a way to say "if in edit mode do this..."?

jgarcia
 
jgarcia replied on at Permalink Best Answer Reply
jgarcia
for anyone else who may be wondering...

<?php
global $c;
if ($c->isEditMode()) { 
  //Do something
}
?>
ScottC replied on at Permalink Reply
ScottC
it gets screwy when moving it around in edit->position mode, so it is best to just render the blockID, the block name and saying something like this is a google calendar that you are moving.
Proteus replied on at Permalink Reply
Proteus
This is also great for sneaking in an extra style sheet whether or not C5 is in edit mode (to, for instance, fix positioning if you have blocks that are covering area buttons).

i.e.:
global $c;
if ($c->isEditMode()) {
print "<link href=\"".$this->getThemePath()."/css/editmode.css\" rel=\"stylesheet\" type=\"text/css\" media=\"all\"/>";
};


thanks jgarcia…
abra100pro replied on at Permalink Reply
abra100pro
IMHO A better solution to have different csses is to check whether you're logged in, otherwise you have to edit the page to see the difference:

<!-- Is the page in EDIT MODE? -->
<?php
global $c;
if ($c->isEditMode()) {print "<link href=\"".$this->getThemePath()."/mainedit.css\" rel=\"stylesheet\" type=\"text/css\" media=\"all\"/>";}
?>
<!-- is the user LOGGED IN?-->
<?php
global $u;
if ($u->isLoggedIn()) {print "<link href=\"".$this->getThemePath()."/mainedit.css\" rel=\"stylesheet\" type=\"text/css\" media=\"all\"/>";}
?>


Shortform:

<!-- Is the page in edit mode? -->
<?php
global $c;
if ($c->isEditMode()) {do something;}
?>
<!-- is the user logged in?-->
<?php
global $u;
if ($u->isLoggedIn()) {do something;}
?>