Block Class Attribute
Permalink
I have a few images on a homepage, and I want the client to be able to change the images from time to time. Right now they are hard coded as:
If I set this to a new block area where they can change the photo, can I make sure that every time they change the images the block will retain the class. I don't really like adding classes through the UI (just don't feel that's a good practice). I know you can wrap blocks like this:
Is their something like?
<img src="<?=$this->getThemePath()?>/img/welcomePhoto1.jpg" alt="" class="welcome-photo" />
If I set this to a new block area where they can change the photo, can I make sure that every time they change the images the block will retain the class. I don't really like adding classes through the UI (just don't feel that's a good practice). I know you can wrap blocks like this:
<?php $a = new Area('sidebar'); $a->setBlockWrapperStart('<div class="box">'); $a->setBlockWrapperEnd('</div>'); $a->display($c); ?>
Is their something like
$a->setBlockClass('welcome-photo');
Could you not just hardcode the class attribute to the div or container the picture will be in?
If I put them in div's, yes, but I was wanting to just leave the img elements by themselves. I don't put anything in div's if I don't need to, to keep the code cleaner.
The way that I would probably do this is with the $area->setCustomTemplate() method.
Then you just copy the view.php from /concrete/blocks/image/view.php to /blocks/templates/welcome_image/view.php and edit it as needed. That way every block of type 'image' added to that area will automatically get that custom template, but still have the capability to be overridden, if needed.
Your template's view.php would be something like
That should do it!
<?php $a = new Area('sidebar'); $a->setBlockWrapperStart('<div class="box">'); $a->setBlockWrapperEnd('</div>'); $a->setCustomTemplate('image','templates/welcome_photo'); $a->display($c); ?>
Then you just copy the view.php from /concrete/blocks/image/view.php to /blocks/templates/welcome_image/view.php and edit it as needed. That way every block of type 'image' added to that area will automatically get that custom template, but still have the capability to be overridden, if needed.
Your template's view.php would be something like
<?php defined('C5_EXECUTE') or die("Access Denied."); ?> <? $f = $this->controller->getFileObject(); $img = Loader::helper('image')->getThumbnail($f,500,400); // whatever your image spec sizes are here if ($altText) { $img->alt = $altText; } else { $img->alt = $f->getDescription(); } ?> <?php if ($externalLink) { ?> <a href="<?php echo $externalLink; ?>" title="<?php echo $img->alt; ?>"> <?php } ?> <img class="welcome-photo" src="<?php echo $img->src; ?>" width="<?php echo $img->width; ?>" height="<?php echo $img->height; ?>" alt="<?php echo $img->alt; ?>" /> <?php if ($externalLink) { ?>
Viewing 15 lines of 17 lines. View entire code block.
That should do it!
Okay, that makes sense. I will try to give it a shot soon, thanks!