Fórum

Add specific class on page

Erick Borges, modificado 10 Anos atrás.

Add specific class on page

Junior Member Postagens: 29 Data de Entrada: 18/12/12 Postagens Recentes
Is there a way to add a specific class for each page in liferay? This class will stand in the body tag, for example.
thumbnail
Amos Fong, modificado 10 Anos atrás.

RE: Add specific class on page

Liferay Legend Postagens: 2047 Data de Entrada: 07/10/08 Postagens Recentes
Hi Erick,

You probably need to do some work in theme here. The body tag is usually in portal_normal.vm so you just need to modify that to pull the CSS class from where you want it defined.
Erick Borges, modificado 10 Anos atrás.

RE: Add specific class on page

Junior Member Postagens: 29 Data de Entrada: 18/12/12 Postagens Recentes
Thank you Amos.

I've found a way to identify the page through page url or the page title. Then I created a condition that adds a class updating the variable "$css_class".

Doing this in portal_normal.vm:

First option, page url:
#if ($theme_display.getURLCurrent().contains("/home") == true)
#set ($css_class = $css_class + " home")
#end

Second option, page title, in case the url doesn't show whatever you want:
#if ($the_title.contains("Home") == true)
#set ($css_class = $css_class + " home")
#end

$theme_display.getURLCurrent() - gets part of url (/web/your-site/your-page);
$the_title - gets page title;
$css_class - just all classes applied on the page.
thumbnail
Thiago Dantas Martins, modificado 9 Anos atrás.

RE: Add specific class on page

New Member Postagens: 4 Data de Entrada: 27/07/10 Postagens Recentes
Erick Borges:

Second option, page title, in case the url doesn't show whatever you want:
#if ($the_title.contains("Home") == true)
#set ($css_class = $css_class + " home")
#end


That second option is just what I need, but in Portuguese we have Page Titles with accents. At the portal I'm working now, the first page's title is "Início", and that piece of code doesn't work for titles with accents like in this case.

I have tried this:
#if ($the_title.contains("Início") == true)
#set ($css_class = $css_class + " inicio")
#end

And also this:
#if ($the_title.contains("Início") == true)
#set ($css_class = $css_class + " inicio")
#end

But without any success.

Can anybody help me with this particular issue?

(I'm a designer.)