block headings

block headings

by John Nystrom -
Number of replies: 19
I want to replace the block headings with jpg or gif files, this are images of text and look a lot more professional.  I looked at replacing the strings with the images but it didn't work.  Anybody got any Ideas?
Average of ratings: -
In reply to John Nystrom

Re: block headings

by David Scotson -

I've only thought about doing this but:

Each block has a unique id (e.g. block_participants), within the header there is a td with the class sideblockheading so it seems possible to create a unique header image to use as a background for that table cell.

#block_participants .sideblockheading { background-image: whatever.jpg;}

Then you could hide the heading text by setting display: none on the floated div that contains it. Therefore you could replace the hidden text with the same words embedded into the background image.

#block_participants .sideblockheading div { display: none;}

Unfortunately the edit controls for the block are also in a div immediately after the title and there is no differentiation between the two in the HTML at the moment. Also, display: none hides the text from screen readers and other accessability aids.

However, with a bit of fiddling with the HTML (just adding a span round the text to be replaced) you could probably use one of the more accessible versions of the Farhner Image Replacement technique.

http://www.stopdesign.com/articles/replace_text/

In reply to David Scotson

Re: block headings

by Luca Bagna -
It's a great tip smile thanks a lot.
I've been playing with this and I've found that, for myself, these strings are correct and work with Firefox and IE  both:

        #block_private_messages .sideblockheading {
            background-image: url(<?PHP echo "$themeurl"?>/whatyoulike.jpg);
            height:22px;
            }
        #block_private_messages .sideblockheading div { display: none;}

Luca
In reply to Luca Bagna

Re: block headings

by David Scotson -

Do you have a public server with this code working? I'd really like to see how it looks.

Also, an idea: It would be very neat if, since you already have PHP in the CSS, you checked the user's language code and looked for a localised image called whatyoulike_en_GB.jpg etc.

And even better would be if that file doesn't exist it defaulted to header_blank.jpg and didn't display:none the div text to allow standard display.

In reply to David Scotson

Re: block headings

by Luca Bagna -
Unfortunately not yet mixed
I hope that the results show up in the attached image (please consider that i've just started playing with this today, so please be kind smile ).
The images used are jpg made with fireworks
Luca
Attachment images.jpg
In reply to Luca Bagna

Re: block headings

by Jeffery Watkins -

wow..... cant wait until I have some free time to make some new themes!!!!

Very, Very, nice work!!!

Jeff

In reply to Jeffery Watkins

Re: block headings

by Jeffery Watkins -
I was playing with this idea this morning.  The problem I run into is that the right and left blocks are different sizes.  So, If I make a 178px wide background for the left blocks, it will not work if that block is on the right.

Any ideas... am I missing something elementary?

Jeff
In reply to Jeffery Watkins

Re: block headings

by Luca Bagna -
Same situation here thoughtful
I've made two templates with two diffent widths, it's the best solution I've found so far.
Luca
In reply to Luca Bagna

Re: block headings

by Jeffery Watkins -

Hi Luca,

I did the same.  The new template system will make all of this obsolete.

Great idea until then though....

Jeff

In reply to Jeffery Watkins

Re: block headings

by David Scotson -

I think it's generally a bad idea to assume pixel-precise widths as that will break badly when users change text or window sizes.

You can take the easy way out and make the header as wide as you think it will ever need to be and position the text so it is still somewhat readable with the narrowest reasonable length.

However, this completely prevents you from doing what Luca has done in his screenshots which is to anchor things (the image and the text) to both sides of the header at the same time.

Unless you:

  • only put the image in the header, and position the text with standard CSS

  • create two images, attaching one to the top-left-hand corner of the entire block and attaching the other to the top-right-hand corner of just the sideblockheading. If they overlap correctly then they will be able to flex slightly without breaking.

Alpha-blended PNGs let you achieve some beautiful effects with that last technique, but a certain browser doesn't support them unfortunately.

In reply to David Scotson

Re: block headings

by Jeffery Watkins -

David,

On my installation of Moodle, the left side blocks are a constant size regardless of screen resolution or window size.  The center column and the right column are set as a percentage.

If I could set the right column to display a constant size, this would work somewhat ok.... except for the fact that when you go to move or delete a block the arrows and such do not show up because of the "display:none" tag...lol.

Jeff

In reply to Jeffery Watkins

Re: block headings

by John Papaioannou -
You can coerce blocks to assume a width greater than what they would actually need by using the preferred_width() member function in each block class (i.e. in each blocks/block_XXX/block_XXX.php file).

The course formats are defaulting to constraining such requests between 180 and 210 pixels, so if you want to go outside that range you have to edit the course formats too (open up any one, it's pretty self-explanatory in the first lines).

Maybe this would help?
In reply to Luca Bagna

Re: block headings

by John Nystrom -
  I still cant get the headings to change.  I used the same code (changed to match my image names and blocks id.  The only thing I can think of is that I cant find the TD tag with the class sideblockheading?  Also how did you change the icons within the block, I have images created for that as well.  Any one please help, I must be missing something simple or I am not recognizing something.

Moodle man In dire need.
In reply to John Nystrom

Re: block headings

by David Scotson -

I'd like to help but I'm not sure I know where you're going wrong.

Is it just this particular header image that's troubling you or are you generally fuzzy on CSS/HTML, or maybe just the way it is used in Moodle?

Can you get simpler CSS to affect the headers e.g. change the background and text color?

As for changing the other images, try looking here:

http://moodle.org/wiki/index.php/Themes

In particular the section about the pix directory.

In reply to Luca Bagna

Re: block headings

by John Nystrom -

What file did you put the code in, I have tried working it into the CSS and also in the block php.

A little help please

In reply to John Nystrom

Re: block headings

by Luca Bagna -
John,
what I've done is:
  • edit the styles.php in your favourite theme.
  • look for the .sideblockheading class
  • under this class insert the following
        #block_private_messages .sideblockheading {
            background-image: url(<?PHP echo "$themeurl"?>/whatyoulike.jpg);
            height:22px;
            }
        #block_private_messages .sideblockheading div { display: none;}

you should insert the above instructions for every heading you have, changing the image file according to the block you're working to.
I hope this helps you
Luca
In reply to Luca Bagna

Re: block headings

by John Nystrom -
Thanks a lot you really have been a great help!



But now I have one more request, where do I look to get rid of the padding inside the block, I want to replace the icons and links with other images, and i have yet it forces the heading to expand because of the padding.  the heading image and the images inside are the same size. I have been looking in the css and in blocks_preferred_width. where do i look?

In reply to John Nystrom

Re: block headings

by John Nystrom -
How do you change the icons, images and text within the blocks.  Where and what code do I need to change.

Thanks for all the help guys.
In reply to John Nystrom

Re: block headings

by Daryl Hawes -
See moodle/blocks/moodleblock.class.php in function add_edit_controls()