Liferay custom page field only gets read in velocity if user is signed in

1.2k views Asked by At

I'm having a strange problem with a Liferay Theme I'm doing. The theme is supposed to present two different menus from the list of navigation items that the portal provides. I wrote a portal_normal.vm in velocity markup and it works okay if the user is signed in to the portal, but not if he or she isn't.

Here's a couple of images of how the theme looks so far. The first one is wrong, it is how the theme gets rendered without logging in, and the second is ok.

I suspect there's something wrong in my markup but I need another pair of eyes to detect what may be the cause, please.

Here are the images: Wrong display (user is not logged in

Correct display

And this is my velocity markkup in portal_normal.vm

    <!DOCTYPE html>

#parse ($init)

<html class="$root_css_class" dir="#language ("lang.dir")" lang="$w3c_language_id">

<head>
    <title>$the_title - $company_name</title>

    <meta content="initial-scale=1.0, width=device-width" name="viewport" />

    $theme.include($top_head_include)
    #js ("$javascript_folder/jquery-1.11.1.min.js")
    #js ("$javascript_folder/bootstrap.affix.min.js")
    #js ("$javascript_folder/jquery.transit.min.js")
    #js ("$javascript_folder/affix.js")
</head>

<body class="$css_class">

<a href="#main-content" id="skip-to-content">#language ("skip-to-content")</a>

$theme.include($body_top_include)
#if ($is_signed_in)
#dockbar()
#end

#set ($teaser = $layout.getExpandoBridge().getAttribute("etiqueta-pagina"))

#if(!$teaser.contains("teaser"))
#set ($header_class = "header-inside")
#else 
#set ($header_class = "")
#end

#if($is_signed_in)
#set ($header_dockbar ="con_dockbar")
#set ($logo_dockbar = "con_dockbar")
#else 
#set ($header_dockbar ="")
#set ($logo_dockbar = "")
#end

<div class="container-fluid" id="wrapper">
    <header id="banner" role="banner" class="$header_class">
        <div id="heading">
            <h1 class="site-title $logo_dockbar" id="logo">
                <a class="$logo_css_class" href="$site_default_url" title="#language_format ("go-to-x", [$site_name])">
                    <img alt="$logo_description" height="$site_logo_height" src="$site_logo" width="$site_logo_width" />
                </a>
</h1>
<div class="header-nav" id="nav-super">
                #if ($show_site_name)
                    <span class="site-name" title="#language_format ("go-to-x", [$site_name])" id="logo-label">
                        $site_name
                    </span>
                #end



            <ul aria-label="#language ("site-pages")" role="menubar">
        #foreach ($nav_item in $nav_items)
            #set ($nav_item_attr_has_popup="")
            #set ($nav_item_attr_selected="")
            #set ($nav_item_css_class = "")
            #set ($etiqueta = $nav_item.getLayout().getExpandoBridge().getAttribute("etiqueta-pagina"))
            #if ($nav_item.isSelected())
                #set ($nav_item_attr_selected="aria-selected='true'")
                #set ($nav_item_css_class = "selected")
            #end

            #if ($nav_item.hasChildren())
                #set ($nav_item_attr_has_popup="aria-haspopup='true'")
            #end
            #if($etiqueta.contains("perfiles"))
            <li class="$nav_item_css_class" id="layout_$nav_item.getLayoutId()" $nav_item_attr_selected role="presentation">
                <a aria-labelledby="layout_$nav_item.getLayoutId()" href="$nav_item.getURL()" $nav_item_attr_has_popup $nav_item.getTarget() role="menuitem"><span>$nav_item.icon() $nav_item.getName()</span></a>
            </li>
            #end
        #end
            </ul>
        </div>
        #if($teaser.contains("teaser")) 
        #*
        *
        *slider
        *
        *#
        <div class="teaser-home">
        <div class="carousel" id="main-slider">
          <div class="carousel__content">
               <div class="item">
                <div class="text">
                  <h2>Cumplimos 40 a&ntilde;os</h2>
                  <p>&iexcl;Estamos de fiesta!</p>
                  <small>
                    <a href="http://40aniversario.cide.edu">
                      Consulta los eventos en el micrositio del 40 aniversario
                    </a>
                  </small>
                </div>
                <img class="slide-full-image" src="$images_folder/slider-aniversario.jpg">
              </div>

            <div class="item">
                <div class="text">
                  <h2>Dossier Acad&eacute;mico</h2>
                  <p>
                    De la Torre de Marfil a la pertinencia
                    <br>
                    <small>
                      David Arellano Gault | Jes&uacute;s F. Hern&aacute;ndez Galicia
                    </small>
                  </p>
                  <small>
                    <a href="http://www.cide.edu/v2/Dossier_DAG-JHG.pdf" target="_blank">Consultar el dossier</a>
                  </small>
                </div>
              <img class="slide-full-image" src="$images_folder/slider-dossier.jpg">
            </div>

            <div class="item">
              <div class="text">
                  <h2>Prof. Juan Rosell&oacute;n:</h2>
                  <p>Financial Transmission Rights</p>
                  <small>
                    <a href="http://www.youtube.com/watch?v=P-SIC9INPFg" target="_blank">Ver video</a>
                  </small>
              </div>
              <img class="slide-full-image" src="$images_folder/slider-juan-rosellon.jpg">
            </div>
            <div class="item">
               <div class="text">
                  <h2>Diplomado en Alta Direcci&oacute;n</h2>
                  <p>21 de noviembre de 2014 al 15 de febrero de 2015</p>
                  <small>
                    <a href="http://e-continua.cide.edu/productinfo.asp?item=92" target="_blank">Consultar Información</a>
                  </small>
                </div>
              <img class="slide-full-image" src="$images_folder/slider-alta-direccion.jpg">
            </div>
            <div class="item">
              <div class="text">
                  <h2>Dr. Claudio L&oacute;pez-Guerra:</h2>
                  <p>Democracy and Disenfranchisement</p>
                  <small>
                    <a href="http://www.youtube.com/watch?v=sXMvCk8S0VE" target="_blank">Ver video</a>
                  </small>
                </div>
              <img class="slide-full-image" src="$images_folder/slider-claudio-lopez.jpg">
            </div>
            <div class="item">
              <div class="text">
                  <h2>Estefanía Vela</h2>
                  <p>El Protocolo LGBTI de la SCJN</p>
                  <small>
                    <a href="http://www.youtube.com/watch?v=IJsZw1SujBg" target="_blank">Ver video</a>
                  </small>
                </div>
              <img class="slide-full-image" src="$images_folder/slider-estefania-vela.jpg">
            </div>
            <div class="item">
              <div class="text text-right">
                  <h2>
                    Novedades Editoriales
                  </h2>
                  <small>
                    <a href="http://www.libreriacide.com">Visita la Librería CIDE</a>
                  </small>
                </div>
              <img class="slide-full-image" src="$images_folder/slider-libros.jpg">
            </div>
            <div class="item">
              <div class="text">
                  <h2>
                    Curso de Amparo: An&aacute;lisis y aplicaci&oacute;n pr&aacute;ctica.
                  </h2>
                  <small>
                    <a href="http://cideenlinea.cide.edu/">Consulta este curso en línea</a>
                  </small>
                </div>
              <img class="slide-full-image" src="$images_folder/slider-curso.jpg">
            </div>
            <div class="item">
              <div class="text">
                <p class="text">
                  Generamos conocimiento cient&iacute;fico con est&aacute;ndares internacionales en ciencias sociales que contribuye a explicar la realidad y resolver problemas
                  <small>
                    <a href="http://boletininvestigacion.cide.edu/">
                      Consulta nuestras investigaciones recientes
                    </a>
                  </small>
                </p>
              </div>
              <img class="slide-full-image" src="$images_folder/slider-2.jpg">
            </div>
            <div class="item">
              <div class="text small">
                  <h2>
                    Programa de difusi&oacute;n de los temas publicados en el apartado de Transparencia Focalizada
                  </h2>
                  <p>
                    En favor de la transparencia, el
                    <acronym>cide</acronym>
                    ofrece orientaci&oacute;n acerca de 5 temas b&aacute;sicos (Programas Docentes, Datos Abiertos, Bolet&iacute;n de Investigaci&oacute;n, Becas, Suscripciones y Venta de Publicaciones, Proyectos de inversi&oacute;n)
                  </p>
                  <small>
                    <a href="/transparencia_focalizada.html">
                      Detalles del programa
                    </a>
                  </small>
                </div>
              <img class="slide-full-image" src="$images_folder/slider-transparencia.jpg">
            </div>
       </div>

        <div class="carousel__nav">
        <a href="#" class="nav nav--left">Prev</a><a href="#" class="nav nav--right">Next</a></div>
        #*
        *
        *Fin del slider
        *
        *#
        #end
</div>
</div>
        #if (!$is_signed_in)
            <a data-redirect="$is_login_redirect_required" href="$sign_in_url" id="sign-in" rel="nofollow">$sign_in_text</a>
        #end

        #if ($has_navigation || $is_signed_in)
            #parse ("$full_templates_path/navigation.vm")
        #end
    </header>

    <div id="content">
        <h2 class="page-title">
                <span>$the_title</span>
        </h2>

        #if ($selectable)
            $theme.include($content_include)
        #else
            $portletDisplay.recycle()

            $portletDisplay.setTitle($the_title)

            $theme.wrapPortlet("portlet.vm", $content_include)
        #end
    </div>

    <footer id="footer" role="contentinfo">
    <div class="pie">
        <ul class="footer-cols">
        <li id="footer-info">
        <a href="http://www.cide.edu" id="logo-footer">Centro de Investigaci&oacute;n y Docencia Econ&oacute;micas</a>
        <p class="privacy-policy-link">
        <a href="http://www.cide.edu.mx/politica_privacidad.htm">Pol&iacute;tica de privacidad</a>
        </p>

            Carretera M&eacute;xico- Toluca 3655 Col. Lomas de Santa Fe 01210 M&eacute;xico, D.F.
            Conmutador: 5727-98-00 Lada sin costo: 01 800 021 2433 (CIDE) | &copy;
        <a href="http://cide.edu.mx/localizacion.htm">Localizaci&oacute;n</a>
        </li>
        <li>
        <h2>Aspirantes</h2>
        <ul>
        <li><a href="https://msicidepdn.cide.edu/opa_solicitudes/">
                Registro en l&iacute;nea
              </a></li>
              <li>
              <a href="http://www.cide.edu/v2/resultadosdeadmision.html">
                Resultados de Admisi&oacute;n
              </a>
            </li>
            <li>
              <a href="http://www.cide.edu/v2/curso_de_nivelacion.html">
                Curso de nivelaci&oacute;n
              </a>
            </li>
            <li>
              <a href="http://www.cide.edu/semana-de-oyentes.php">
                Semana de oyentes
              </a>
            </li>
            <li>
              <a href="http://www.cide.edu/v2/programas_docentes.html">
                Programas Docentes
              </a>
            </li>
              </ul>
        </li>
        <li>
          <h2>Investigadores</h2>
          <ul>
            <li>
              <a href="http://www.cide.edu/v2/divisiones_academicas.html">
                Divisiones Acad&eacute;micas
              </a>
            </li>
            <li>
              <a href="#">
                Programas Interdisciplinarios
              </a>
            </li>
            <li>
              <a href="#">
                Programas Especiales
              </a>
            </li>
            <li>
              <a href="http://www.cide.edu/v2/publicaciones.html">
                Publicaciones
              </a>
            </li>
            <li>
              <a href="http://boletininvestigacion.cide.edu/">Bolet&iacute;n de Investigaci&oacute;n</a>
            </li>
            <li>
              <a href="https://msicidepdn.cide.edu/rh_dtsactualiza_externos/" target="_blank">
                Profesores externos
              </a>
            </li>
          </ul>
        </li>
        <li>
          <h2>Estudiantes</h2>
          <ul>
            <li>
              <a href="http://www.cide.edu/v2/licenciaturas.html">Licenciatura</a>
            </li>
            <li>
              <a href="http://www.cide.edu/v2/maestrias.html">Maestr&iacute;as</a>
            </li>
            <li>
              <a href="http://dpp.cide.edu/">Doctorado</a>
            </li>
            <li>
              <a href="http://e-continua.cide.edu/">Educaci&oacute;n Continua</a>
            </li>
          </ul>
        </li>
        <li>
          <h2>Recursos</h2>
          <ul>
            <li>
              <a href="http://biblioteca.cide.edu/">Biblioteca</a>
            </li>
            <li>
              <a href="http://www.libreriacide.com/">Librer&iacute;a</a>
            </li>
            <li>
              <a href="http://www.biiacs.cide.edu/">BIIACS</a>
            </li>
          </ul>
        </li>
        <li>
          <h2>Administrativos</h2>
          <ul>
            <li>
              <a href="http://portal.cide.edu/">
                Intranet
              </a>
            </li>
            <li>
              <a href="http://cide.edu.mx/directorio.php">
                Directorio telef&oacute;nico
              </a>
            </li>
          </ul>
        </li>
        <li id="transparencia">
          <h2>Transparencia</h2>
          <ul>
            <li>
              <a href="http://www.cide.edu/v2/transparencia.html">
                Normatividad en materia de transparencia
              </a>
            </li>
            <li>
              <a href="http://www.cide.edu.mx/comitedeinformacion.htm">
                Comit&eacute; de informaci&oacute;n
              </a>
            </li>
            <li>
              <a href="http://www.cide.edu.mx/transparencia_focalizada.html">
                Transparencia focalizada
              </a>
            </li>
            <li>
              <a href="http://www.cide.edu/v2/sfp-cide/indicadores.php">
                Indicadores de Programas Presupuestarios
              </a>
            </li>
            <li>
              <a href="http://www.cide.edu.mx/sfp-cide/recomendaciones.htm">
                Recomendaciones Dirigidas al CIDE
              </a>
            </li>
            <li>
              <a href="http://www.cide.edu.mx/sfp-cide/estudiosyopiniones.htm">
                Estudios y Opiniones
              </a>
            </li>
            <li>
              <a href="http://www.cide.edu.mx/sfp-cide/rendiciondecuentas.htm">
                Rendici&oacute;n de Cuentas
              </a>
            </li>
            <li>
              <a href="http://www.cide.edu.mx/sfp-cide/participacion-ciudadana.php">
                Participaci&oacute;n Ciudadana
              </a>
            </li>
          </ul>
        </li>
        <br style="clear:both" />
        </ul>
        <br style="clear:both" />
        </div>
        <br style="clear:both" />
    </footer>
</div>

$theme.include($body_bottom_include)

$theme.include($bottom_include)

</body>

</html>

Thanks in advance for taking the time to read this.

By the way, the line that's apparently not getting read is this one #if($etiqueta.contains("perfiles")) <li class="$nav_item_css_class" id="layout_$nav_item.getLayoutId()" $nav_item_attr_selected role="presentation"> <a aria-labelledby="layout_$nav_item.getLayoutId()" href="$nav_item.getURL()" $nav_item_attr_has_popup $nav_item.getTarget() role="menuitem"><span>$nav_item.icon() $nav_item.getName()</span></a> </li> #end

2

There are 2 answers

0
Pawel Kruszewski On BEST ANSWER

or if you don't care about permissions on this custom field you can as well try to use following method:

$nav_item.getLayout().getExpandoBridge().getAttribute("etiqueta-pagina",false))

This method ignores custom field permissions.

br, Pawel

1
Laxman Rana On

From the code it seems like you have created a custom attribute for page and based on that you are processing something in vm file. You need to assign guest view permission for custom attribute you created from liferay control.

HTH