[Seaside] Links and Components doubts

Julian Fitzell jfitzell at gmail.com
Thu Oct 23 17:10:58 UTC 2008


On Thu, Oct 23, 2008 at 7:38 PM, Sebastian Van Lacke
<svanlacke at caesarsystems.com> wrote:
> Hello,
>
> I'm from Argentina and I am working on a Seaside project. I don't speak
> English very well, so I hope you understand...

Hi! Not to worry... plus your English sounds totally fluent. I don't
think I saw a single mistake in your whole email. Seriously.

> I need to recreate an old site using Seaside, and I and I'm having problems
> with the structure of the site.
>
> My page has a header, menu, and a footer (which are repeated throughout the
> site) and a body that changes for each page of the site,
> depending on the option chosen on the menu.
>
> CSRootComponent>>renderContentOn: html
>  html div
>   id:'allContent';
>   with:[
>    html render: header.
>    html render: menu.
>    self renderBodyOn: html.
>    html render: footer.
>   ]
>
> ---------------------------------------------------------------------------------------------
> The component menu, displays a horizontal menu with links to different pages
> on the site.
>
> CSMenuComponent>>renderContentOn: html
>  html div
>   id: 'menu';
>   with: [
>    html unorderedList: [
>     self  renderMenuItemsOn: html.
>     ].
>   ].
> ---------------------------------------------------------------------------------------------
> CSMenuComponent>>renderMenuItemsOn: html
>
>  menuItems do: [:item |
>   html listItem with: [
>    html anchor
>     callback: item value;
>     with: item key.
>   ].
>  ]
>
> ----------------------------------------------------------------------------------------------
> CSMenuComponent>>initialize
>
>  super initialize.
>  menuItems := OrderedCollection new.
>  self addMenuItem: 'Company Info' withBlock: [ self companyInfo].
>  self addMenuItem: 'Products' withBlock: [ self products ].
>  self addMenuItem: 'Downloads' withBlock: [ self downloads ].
>  self addMenuItem: 'Resources' withBlock: [ self resources ].
>  self addMenuItem: 'Support' withBlock: [ self support ].
>  self addMenuItem: 'Contact Us' withBlock: [ self contactUs ].
>
> ----------------------------------------------------------------------------------------------
>
> where each of the links should display a new page with the same structure as
> before, but with a different body.

Everything looks totally reasonable so far...

> It is right to create a component for each link ? For example,
> CSCompanyInfoComponent for companyInfo link.
> How I call that component, from CSMenuComponent>>companyInfo method, to
> render in a new page??
> I am confused by the fact that I don't have a renderCanvas to speak in that
> context.

Yes, you likely want a component for each menu item.

What you probably want is a "currentItem" instance variable or
something to store the currently viewed page (if you want the back
button to work, you'll want to make sure to use #updateStates: to
register your component for backtracking). Also make sure you return
any components you are storing in #children. You could either create
new components each time the menu changes or you could keep a
dictionary of them keyed by symbols or something (this might actually
help if you need to visibly mark the currently selected menu item
somehow).

In any case, in your menu callbacks you put the correct item in the
currentItem instvar, and then in the render phase you just do "html
render: currentItem".

There are other ways to do it but that's probably the simplest.

Hope that's clear,

Julian


More information about the seaside mailing list