Forum Discussion

omygoodness's avatar
8 years ago

Adding conditions in layouts

Is there a way to add IF condition to layouts? I would like to modify layout of viewprofilepage and create two separate views in one layout:

 

1) view that is visible only for user lets call it "private profile" where I would like to hide side content and set rest of content to 100% width

2) view that is visible for all users lets call it "public profile" where I would like to show side content with contact and status informations.

 

For now both views are using same layout viewprofilepage and in private view sidebar is empty but still has width.

  • ChiaraS's avatar
    ChiaraS
    Lithium Alumni (Retired)

    Hi,

     

    you could try to replace the quilt in the Page Initialization, adding something like this (untested):

     

    <#if page.name == "ViewProfilePage">
    	<#if page.context.user.id == user.id>
    		${http.response.replaceQuilt("ViewProfilePage","ViewProfilePage.User")}
    	</#if>
    </#if>

     

    and creating a custom page ViewProfilePage.User with the different layout...

     

     

    • jferrandis's avatar
      jferrandis
      Expert

      i think the simplest way is to contextualize your "private" component with a if condition

       

      for custom components just put 

       

      <#if page.context.user.id == user.id >
      .. my custom components ...
      </#if>

       

       

      For standard component you will have to create a custom one one to ovverride it :

      --> name it : standard-component-id@override

      --> add your conditionr before

       

      <#if page.context.user.id == user.id >
      <@delegate /> <#-- this call the standard component -->
      </#if>