Adding CSS classes to the <body> element

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
PayBas
Former Team Member
Posts: 930
Joined: Thu May 25, 2006 12:37 am

Adding CSS classes to the <body> element

Post by PayBas »

I was wondering what the best method would be for an extension to add classes to the <body> element (without using JavaScript).

The body element (for proSilver) looks like this:

Code: Select all

<body id="phpbb" class="nojs section-{SCRIPT_NAME} {S_CONTENT_DIRECTION}">
So the most logical thing would probably be to append a string to {SCRIPT_NAME} (with an added space to separate them of course).

So how do we do this?

I used the event listener 'core.page_header' in combination with:
$this->template->append_var("SCRIPT_NAME", " foo");

But this doesn't work, I think because SCRIPT_NAME is inside: template->context->tpldata, whereas append_var acts on template->context->rootref.

Any ideas?

I know I could probably use a DEFINE template operation and put it in <!-- EVENT overall_header_head_append -->, but I'd rather do it straight from the core listener.
User avatar
PayBas
Former Team Member
Posts: 930
Joined: Thu May 25, 2006 12:37 am

Re: Adding CSS classes to the <body> element

Post by PayBas »

Ah ok that was silly. The event core.page_header is triggered before the template variables are assigned. So SCRIPT_NAME simply gets overwritten.

I guess we need a new event.
Post Reply

Return to “Extension Writers Discussion”