<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>how to get current url in template using freemarker in liferay</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=94696723" />
  <subtitle>how to get current url in template using freemarker in liferay</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=94696723</id>
  <updated>2026-05-13T23:29:09Z</updated>
  <dc:date>2026-05-13T23:29:09Z</dc:date>
  <entry>
    <title>RE: how to get current url in template using freemarker in liferay</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114771431" />
    <author>
      <name>Roshan Qureshi</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=114771431</id>
    <updated>2019-08-16T11:43:31Z</updated>
    <published>2019-08-16T11:43:31Z</published>
    <summary type="html">I have same web content on two pages. I used above but getting same url on both pages.&lt;br /&gt;If I do any changes in template and try from the home page its giving me  home page url&lt;br /&gt;But when go to another page projects - it also gives home page url only.&lt;br /&gt;&lt;br /&gt;If I again change something in template and visit first projects page -it gives me project url but after that home page also gives project url.&lt;br /&gt;It seems some bug.</summary>
    <dc:creator>Roshan Qureshi</dc:creator>
    <dc:date>2019-08-16T11:43:31Z</dc:date>
  </entry>
  <entry>
    <title>RE: how to get current url in template using freemarker in liferay</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=109101910" />
    <author>
      <name>Goran Marinkovic</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=109101910</id>
    <updated>2018-05-29T23:42:23Z</updated>
    <published>2018-05-29T23:42:23Z</published>
    <summary type="html">if your url   bla bla like:  &lt;strong&gt;&lt;span style="color: #fd0101"&gt;web-serbia/gest/organization&lt;/span&gt;&lt;/strong&gt;   &lt;br /&gt;&lt;br /&gt; &lt;strong&gt;&lt;span style="color: #fc0808"&gt;I&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;lt;h1&amp;gt;${themeDisplay.getURLCurrent()}&amp;lt;/h1&amp;gt;&lt;/strong&gt;    you get :  &lt;strong&gt;web-serbia/gest/organization&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   &lt;strong&gt;&lt;span style="color: #fc0808"&gt; II&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;lt;h2&amp;gt;${themeDisplay.getLayout().getFriendlyURL()}&amp;lt;/h2&amp;gt; &lt;/strong&gt;   you get:  &lt;strong&gt;/organization&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;strong&gt;&lt;span style="color: #fc0808"&gt;III&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&amp;lt;h3&amp;gt;${&amp;#34;${themeDisplay.getLayout().getFriendlyURL()}&amp;#34;?remove_beginning(&amp;#34;/&amp;#34;)}&amp;lt;/h3&amp;gt;&lt;/strong&gt;  you get:  &lt;strong&gt;organization&lt;/strong&gt;</summary>
    <dc:creator>Goran Marinkovic</dc:creator>
    <dc:date>2018-05-29T23:42:23Z</dc:date>
  </entry>
  <entry>
    <title>RE: how to get current url in template using freemarker in liferay</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=97443889" />
    <author>
      <name>Massimo Bevilacqua</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=97443889</id>
    <updated>2017-10-23T14:55:34Z</updated>
    <published>2017-10-23T14:55:34Z</published>
    <summary type="html">It works,&lt;br /&gt;maybe you missed this &lt;br /&gt;&lt;blockquote&gt;In order to use &amp;#34;staticUtil&amp;#34; you must delete the variable restiriction&lt;/blockquote&gt;&lt;br /&gt;or this:&lt;br /&gt;&lt;blockquote&gt;(this is for liferay 7, if you are using liferay 6 use &amp;#34;com.liferay.portal.service.ServiceContextThreadLocal&amp;#34;)&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;A server restart it could be necessary.&lt;br /&gt;&lt;br /&gt;ThemeDisplay is available retrived in this way.&lt;br /&gt;&lt;br /&gt;You will find below the output of the previously code pasted in a simple template&lt;br /&gt;&lt;br /&gt;&lt;img src="http://i65.tinypic.com/2hzqc9.png" /&gt;</summary>
    <dc:creator>Massimo Bevilacqua</dc:creator>
    <dc:date>2017-10-23T14:55:34Z</dc:date>
  </entry>
  <entry>
    <title>RE: how to get current url in template using freemarker in liferay</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=97384143" />
    <author>
      <name>Dayanand Tiwari</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=97384143</id>
    <updated>2017-10-22T04:48:08Z</updated>
    <published>2017-10-22T04:48:08Z</published>
    <summary type="html">It fails in the first line saying evoluated to null or missing..and i think themeDisplay object also not available in template script.</summary>
    <dc:creator>Dayanand Tiwari</dc:creator>
    <dc:date>2017-10-22T04:48:08Z</dc:date>
  </entry>
  <entry>
    <title>RE: how to get current url in template using freemarker in liferay</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94728785" />
    <author>
      <name>Massimo Bevilacqua</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94728785</id>
    <updated>2017-09-11T07:37:33Z</updated>
    <published>2017-09-11T07:37:33Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi,&lt;br&gt;&lt;br&gt;try this:&lt;br&gt;In order to use "staticUtil" you must delete the variable restiriction&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;&amp;amp;lt;#assign serviceContext = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"].getServiceContext()&amp;amp;gt;
&amp;amp;lt;#assign themeDisplay = serviceContext.getThemeDisplay() /&amp;amp;gt;
&amp;lt;div id="CurrentUrl"&amp;gt;
CurrentURL:  &amp;amp;lt;#assign currentUrl = themeDisplay.getPortalURL() + themeDisplay.getURLCurrent() /&amp;amp;gt;
${currentUrl}
&amp;lt;/div&amp;gt;

&amp;amp;lt;#if currentUrl?contains("yourString")&amp;amp;gt;
It contains "yourString"
&amp;amp;lt;#else&amp;amp;gt;
It doesn't 'contains "yourString"
&amp;lt;!--#if--&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;(this is for liferay 7, if you are using liferay 6 use "com.liferay.portal.service.ServiceContextThreadLocal")&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Massimo Bevilacqua</dc:creator>
    <dc:date>2017-09-11T07:37:33Z</dc:date>
  </entry>
  <entry>
    <title>how to get current url in template using freemarker in liferay</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94696722" />
    <author>
      <name>Dayanand Tiwari</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94696722</id>
    <updated>2017-09-09T12:55:18Z</updated>
    <published>2017-09-09T12:55:18Z</published>
    <summary type="html">how to get current url in template using freemarker in liferay.&lt;br /&gt;&lt;br /&gt;I have tried multiple things but getting errors. Can anyone please provide me that working code to get the current url in  template.&lt;br /&gt;Mainly I have to compare where this url contains a particular string or not in my application.</summary>
    <dc:creator>Dayanand Tiwari</dc:creator>
    <dc:date>2017-09-09T12:55:18Z</dc:date>
  </entry>
</feed>
