Styling/Modifying an existing block

Permalink
First of all I'm fairly new to C5 and not a full time web dev. But the more I learn about C5 the more I like it. :)

I downloaded the free Login/Logout Link block from the market place. The them I am using has CSS button classes that can be applied to text in a content block. when applied the to the block the button class produced a button that spanned the width of the area rather than being sized according to the width of the button text and centered in the area.

I experimented with the view.php file and finally got the desired result. What I have works just fine but I believe there is a better or C5 way of doing this that preserves the original block.

This could be a good opportunity to learn a little more about C5. So I am looking for a little advice or direction with regard to C5 best practice. Any input will be greatly appreciated.

view.php
<?php  defined('C5_EXECUTE') or die("Access Denied."); ?>
<div style="margin: 0px auto; width: 125px;">
   <a href="<?php  echo $url;?>"><span class="btn btn-primary"><?php echo $label?></span></a> 
</div>

 
hutman replied on at Permalink Best Answer Reply
hutman
There are two ways that I would suggest to do this differently. I'm assuming you're using 5.7, these instructions would be a little different if it was 5.6

1) If you want this style applied every single block of this type you could just copy the view.php from /packages/package_name/blocks/block_name/view.php to /application/blocks/block_name/view.php

2) If you only want these styles in certain places not everywhere you could create a custom template, to do that you would copy /packages/package_name/blocks/block_name/view.php to /application/blocks/block_name/templates/custom_template_name.php and then on your block you would go to the gear icon and under Custom Template select your custom template from the dropdown (if it isn't there clear your cache).
RickJ replied on at Permalink Reply
Thank you very much, that's exactly what I was looking for. Jordif already told me about #1 and that worked great. I'm thrilled to learn about #2 because I had been wondering about how to make custom block templates but hadn't yet found enough time to pursue it specifically.

Since we are on the subject may I ask if custom page templates are created in the same or similar manner?

I feel that I really made the right choice to go with C5,
RickJ replied on at Permalink Reply
Thank you very much, that's exactly what I was looking for. Jordif already told me about #1 and that worked great. I'm thrilled to learn about #2 because I had been wondering about how to make custom block templates but hadn't yet found enough time to pursue it specifically.

Since we are on the subject may I ask if custom page templates are created in the same or similar manner?

I feel that I really made the right choice to go with C5,