How to check if current page is the homepage from JSP?How to check if current page is the homepage from JSP?https://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=683564402024-03-28T15:33:26Z2024-03-28T15:33:26ZRE: How to check if current page is the homepage from JSP?Tayyab Zafarhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1193167102020-06-05T08:29:57Z2020-06-05T08:29:57ZIn Liferay 7, you can check for the homepage in the freemarker like this:<br /><br /><br /># file: themes/your-theme/init_custom.ftl<br /><br /><#assign<br /> home_page_urls = ["/", "/en", "/en/", "/web/guest", "/web/guest/"]<br /> current_url = htmlUtil.escape(theme_display.getURLCurrent())<br /> is_home_page = home_page_urls?seq_contains(current_url)<br />/><br /><br /><#if is_home_page><br /> <#assign css_class = css_class + " your-custom-class" /><br /></#if>Tayyab Zafar2020-06-05T08:29:57ZRE: How to check if current page is the homepage from JSP?Fernando Cabrerahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=685925212016-01-25T20:02:53Z2016-01-25T20:02:53ZWell, for me the homepage is the one that I visualize when I access without specified any particular page, example: Enter URL http://localhost:8080/web/sitename or when In "My Sites" menu I select one option.<br /><br />I think it is possible to create that method but it probably has many considerations like type of page, user permissions, display order, and maybe more things that I ignore. The answer that I was looking for was to an specific method or for an alternative workaround.<br /><br />About the maintainability, custom solutions are not exempted to be affected because they are based on API that could change, it is better merge a bug solution that make a custom bug fix, worst is ignore that there is a bug, but that is off-topic.<br /><br />Thank you for interest in the question, it is still open in case that someone gives an absolute answer, in the meantime I will use the maximized condition because client don't care about code details, just about due dates. <img alt="emoticon" src="@theme_images_path@/emoticons/unsure.gif" >Fernando Cabrera2016-01-25T20:02:53ZRE: How to check if current page is the homepage from JSP?Olaf Kockhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=684102412016-01-23T08:57:44Z2016-01-23T08:57:44ZYou got me on the "extra code", that's right. What I intended to say is: Without extra conditional code.<br /><br />I expect portlets that behave differently based on the criteria you give to be hard to maintain - and you've seen&described the problems in your answer quite well: What's the criteria for being on "the homepage" and what counts as "the homepage". Once that's codified in Java, in a plugin changing the default behaviour of a portlet, any update to your opinion of what makes up the homepage requires an update. Further, any update on Liferay's side to the portlet (e.g. bugfix) will require you to merge your customization with the updated version. <br /><br />How much easier to maintain is it to just manually determine that one page is a homepage, while another one is not, and just drop a different portlet on it.<br /><br />You have yet another option - AFAIK even when you're going with the "maximized" state: Utilize CSS to style the maximized portlet differently. This will provide you with less code customization and just effect the appearance.Olaf Kock2016-01-23T08:57:44ZRE: How to check if current page is the homepage from JSP?Fernando Cabrerahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=683753622016-01-22T21:41:25Z2016-01-22T21:41:25Z<html><head></head><body><div class="quote-title">Olaf Kock:</div><blockquote>Your problem can be solved without any extra code: Just create a portlet that does what you want it to do</blockquote><br>I don't see how creating a custom portlet is a solution without any extra code. <img alt="emoticon" src="@theme_images_path@/emoticons/big_grin.gif"><br><br>Sarcasm apart, thank you for your reply but it is not an option because we are talking about the login portlet, a very good functionality already available and it is not my intention to re-write it (completely) thats the idea to have hook projects, right?<br><br>@Julien Mourad I tried that methods in JSP<br><br><pre><code>&lt;%= themeDisplay.getURLHome() %&gt;</code></pre>Produces this output: <strong>http://localhost:8080/web/guest</strong><br><br><pre><code>&lt;%= themeDisplay.getPortalURL() + themeDisplay.getURLCurrent() %&gt;</code></pre>Produces five possible outputs depending on how I write the URL in the browser:<br><strong>http://localhost:8080/<br>http://localhost:8080/web/guest<br>http://localhost:8080/web/guest/<br>http://localhost:8080/web/guest/welcome<br>http://localhost:8080/web/guest/welcome/</strong><br><br>It get worse when I tried with another site: <strong>http://localhost:8080/web/sitename</strong> <em>vs</em> <strong>http://localhost:8008/web/guest</strong><br><br>My guess is that there is not an utility method that accomplish what I want. Now I'm doing it with another approach:<br><pre><code><c:choose>
<c:when test="<%= windowState.equals(WindowState.MAXIMIZED) %>">
<!-- existent code -->
</c:when>
<c:otherwise>
<!-- new code -->
</c:otherwise>
</c:choose></code></pre></body></html>Fernando Cabrera2016-01-22T21:41:25ZRE: How to check if current page is the homepage from JSP?Olaf Kockhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=683667802016-01-22T20:03:36Z2016-01-22T20:03:36Z<html><head></head><body>good that you mention you're a freemarker guy... You might want to correct the string comparison to use <span style="font-family: Courier New">.equals()</span> instead of == (which tests for identity in Java). <br><br>;)<br><br><pre><code>if(currentURL.equals(homeURL)) {...</code></pre></body></html>Olaf Kock2016-01-22T20:03:36ZRE: How to check if current page is the homepage from JSP?Julien Mouradhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=683665692016-01-22T19:55:10Z2016-01-22T19:55:10Z<html><head></head><body>In case you don't want to move forward with creating a new portlet, you can do this (forgive my syntax or poor java code, i work with themes and freemarker)<br><pre><code>ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
String currentURL = themeDisplay.getPortalURL() + themeDisplay.getURLCurrent();
String homeURL = themeDisplay.getURLHome();
if( currentURL == homeURL){
// new code
}
else{
// current code
}</code></pre></body></html>Julien Mourad2016-01-22T19:55:10ZRE: How to check if current page is the homepage from JSP?Olaf Kockhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=683664992016-01-22T19:49:07Z2016-01-22T19:49:07Z<html><head></head><body>Your problem can be solved without any extra code: Just create a portlet that does what you want it to do on the homepage - and add it to the homepage. Then create a second portlet that shows "something new" and add it on any other page. Problem solved, resulting portlets easily maintainable and well reusable under all kinds of circumstances.<br><br>To add something in the direction of your original question: In order to determine the current page from within a portlet, <a href="https://docs.liferay.com/portal/6.2/javadocs/com/liferay/portal/theme/ThemeDisplay.html">themeDisplay</a> is your friend: <br><br><pre><code>ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);</code></pre></body></html>Olaf Kock2016-01-22T19:49:07ZHow to check if current page is the homepage from JSP?Fernando Cabrerahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=683564392016-01-22T16:47:35Z2016-01-22T16:47:35ZHello, let me give you some context to my issue before addressing the question in the title:<br /><br />The current site design consist in some public pages but in no one the login portlet is added, to sign in, the user has to make clic on the link in the dockbar and that redirects to some empty page but with the maximized portlet. There is already a hook installed in the portal to modify the appearance of the login form. Now, our client ask me to show the login in the home page but with a very different design and even behavior, the dockbar link must continue showing the login portlet as it does at this moment.&l