[Seaside] Fill background with image?

Esteban A. Maringolo emaringolo at gmail.com
Sun Dec 4 22:32:55 CET 2005


2005/12/4, Marcus Pedersén <marcus.pedersen at comhem.se>:
> Thanks that was what I was after! Yes, the background of my webpage.
> I tried:
> style
>        ^ 'body { background-image: url(C:\....\...\background.jpg) } '
> and:
> style
>        ^ 'body { background-image: url(C:\....\...\background.gif) } '
> and:
> style
>        ^ 'body { background-image: anImageForm } '
>
> but neither of them worked.
> What am I doing wrong or isn't it working?
> Many thanks in advance!

To use an image obtained from a Form (a Squeak one), you have to
generate a valid URL for that form. Sadly, the style of the component
is obtained before that the render begins, and with no context
available, so a quick&dirty solution would be:


renderContentOn: html
  "Renders receiver on an html generator."
html attributeAt: 'type' put: 'text/css'.
html tag: 'style' do: [
  html text: (
      'body { background-image: url('
       , (self context urlForDocument: aForm)
       , '); }'
   )
].
" rest of your code."

This will generate a separate document handler (and an url for this)
each time the component is rendered, so you can cache the generated
url and use them instead of generating them each time. If not, the web
browser won't cache the generate image, downloading the background
each time.

Another solution, more elegant, would be to have a separate, static
file serving resource, and then point your styles url's to that
resource. i.e. have a "http://youhost/pics/" which is a resource that
directly maps to a directory in the web server.

Then you can apply the background style using:

style
  "Answer a string containing the CSS style for the receiver."

  ^'body { background-image: url(''/pics/yourPicture.png'') }'


I don't know how you can set a separate resource server on Squeak, in
VW with WebToolkit you can do it, and with Swazoo (VW, Squeak, and
Dolphin) can be done using a FileResource.


--
Esteban A. Maringolo
eMaringolo at gmail.com


More information about the Seaside mailing list