<?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>Freemarker: get Asset Publisher entry URL without version number</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=117585399" />
  <subtitle>Freemarker: get Asset Publisher entry URL without version number</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=117585399</id>
  <updated>2026-04-04T14:31:45Z</updated>
  <dc:date>2026-04-04T14:31:45Z</dc:date>
  <entry>
    <title>RE: Freemarker: get Asset Publisher entry URL without version number</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117604142" />
    <author>
      <name>Andrew Jardine</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117604142</id>
    <updated>2019-10-30T16:27:19Z</updated>
    <published>2019-10-30T16:27:19Z</published>
    <summary type="html">Hi Alessandro,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Yeah, I believe versioning was added to a few more of the models since 7.0 was released, which probably has something to do with the changes. Odd though that Liferay didn&amp;#39;t include a configuration for such a change. At any rate, your solution is much simpler that is for sure. One thing though, on the off chance that the version number is NOT there again (like in the next release or something &lt;img alt="emoticon" src="@theme_images_path@/emoticons/happy.gif" &gt;), it might be an idea to use a regex for the version number so that you don&amp;#39;t accidentally lop-off the end of the url &lt;img alt="emoticon" src="@theme_images_path@/emoticons/happy.gif" &gt;</summary>
    <dc:creator>Andrew Jardine</dc:creator>
    <dc:date>2019-10-30T16:27:19Z</dc:date>
  </entry>
  <entry>
    <title>RE: Freemarker: get Asset Publisher entry URL without version number</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117603802" />
    <author>
      <name>Alessandro Candini</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117603802</id>
    <updated>2019-10-30T16:22:10Z</updated>
    <published>2019-10-30T16:22:10Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Thank you, Andrew, I see...but this appended version was added recently, because in version 7.0 it was not present.&lt;br&gt;I solved with the following snippet:&lt;br&gt;&lt;pre&gt;&lt;code&gt;&amp;amp;lt;#list entries as curEntry&amp;amp;gt;
&amp;amp;nbsp; &amp;amp;lt;#assign urlViewInContext = curEntry.getAssetRenderer().getURLViewInContext(renderRequest, renderResponse, currentURL) /&amp;amp;gt;
&amp;amp;nbsp; &amp;amp;lt;#assign versionCharIdx = urlViewInContext?last_index_of("/") - 1 /&amp;amp;gt;
&amp;amp;nbsp; &amp;amp;lt;#assign urlView = urlViewInContext?string[0..versionCharIdx] /&amp;amp;gt;
&amp;amp;nbsp; &amp;lt;a href="${urlView}" target="_self"&amp;gt;${curEntry.getTitle(locale)}&amp;lt;/a&amp;gt;
&amp;lt;!--#list--&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Alessandro Candini</dc:creator>
    <dc:date>2019-10-30T16:22:10Z</dc:date>
  </entry>
  <entry>
    <title>RE: Freemarker: get Asset Publisher entry URL without version number</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117588786" />
    <author>
      <name>Andrew Jardine</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117588786</id>
    <updated>2019-10-28T17:52:46Z</updated>
    <published>2019-10-28T17:52:46Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi Alessandro --&lt;br&gt;&lt;br&gt;Looks like you are stuck with it, sort of. If you look at the JournalArticleAssetRenderer you will see this code (and where the version is added).&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;[code]@Override
public String getURLViewInContext(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      String noSuchEntryRedirect)
   throws Exception {

   ThemeDisplay themeDisplay =
      (ThemeDisplay)liferayPortletRequest.getAttribute(
         WebKeys.THEME_DISPLAY);

   Layout layout = _article.getLayout();

   if (layout == null) {
      layout = themeDisplay.getLayout();
   }

   Group group = themeDisplay.getScopeGroup();

   if (!_isShowDisplayPage(group.getGroupId(), _article)) {
      String hitLayoutURL = getHitLayoutURL(
         layout.isPrivateLayout(), noSuchEntryRedirect, themeDisplay);

      if (Objects.equals(hitLayoutURL, noSuchEntryRedirect)) {
         hitLayoutURL = getHitLayoutURL(
            !layout.isPrivateLayout(), noSuchEntryRedirect,
            themeDisplay);
      }

      return hitLayoutURL;
   }

   if (group.getGroupId() != _article.getGroupId()) {
      group = GroupLocalServiceUtil.getGroup(_article.getGroupId());
   }

   if (_assetDisplayPageFriendlyURLProvider != null) {
      String friendlyURL =
         _assetDisplayPageFriendlyURLProvider.getFriendlyURL(
            getClassName(), getClassPK(), themeDisplay);

      if (Validator.isNotNull(friendlyURL)) {
         return friendlyURL;
      }
   }

   String groupFriendlyURL = PortalUtil.getGroupFriendlyURL(
      LayoutSetLocalServiceUtil.getLayoutSet(
         group.getGroupId(), layout.isPrivateLayout()),
      themeDisplay);

   StringBundler sb = new StringBundler(5);

   sb.append(groupFriendlyURL);
   sb.append(JournalArticleConstants.CANONICAL_URL_SEPARATOR);
   sb.append(_article.getUrlTitle(themeDisplay.getLocale()));
   sb.append(StringPool.SLASH);
   sb.append(_article.getVersion());

   return PortalUtil.addPreservedParameters(themeDisplay, sb.toString());
}
&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;Unfortunately, there is no logic around the version (something like a configuration setting or a property to toggle it on and off) which means I think the out of the box is with the version and that's it.&amp;nbsp; There is something you could try though, if you don't want to use the freemarker bult-ins. You COULD choose to create an override for the &lt;strong&gt;JournalArticleAssetRendererFactory&lt;/strong&gt;&amp;nbsp;and then in that override return you own CustomJournalArticleRenderer, which would basically be identifcal, except remove the line where the version is added to the string bundler.&amp;nbsp;&lt;br&gt;&lt;br&gt;Unfortunately, I don't think that you can extend the JournalArticleAssetRenderer that Liferay provides out of the box (it doesn't appear to be exported?) which means you either have to copy the code, or use David's trick for forcing packages to be exported. Either way, you should give some thought to the approach because it means that future changes to the JournalArticleAssetRenderer may require you to intervene to take advantage of them. Freemaker string functions, as you are doing right now, maybe in fact be your safest bet.&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Andrew Jardine</dc:creator>
    <dc:date>2019-10-28T17:52:46Z</dc:date>
  </entry>
  <entry>
    <title>Freemarker: get Asset Publisher entry URL without version number</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117585398" />
    <author>
      <name>Alessandro Candini</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117585398</id>
    <updated>2019-10-28T16:25:40Z</updated>
    <published>2019-10-28T16:25:40Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;In Lilferay 7.2 CE GA1, I use the following Widget Template for an Asset Publisher:&lt;br&gt;&lt;pre&gt;&lt;code&gt;&amp;amp;lt;#list entries as curEntry&amp;amp;gt;
&amp;amp;nbsp; &amp;amp;lt;#assign urlViewInContext = curEntry.getAssetRenderer().getURLViewInContext(renderRequest, renderResponse, currentURL) /&amp;amp;gt;
&amp;amp;nbsp; &amp;lt;a href="${urlViewInContext}" target="_self"&amp;gt;${curEntry.getTitle(locale)}&amp;lt;/a&amp;gt;
&amp;lt;!--#list--&amp;gt;
&lt;/code&gt;&lt;/pre&gt;This creates the following entry URL:&amp;nbsp;&lt;em&gt; http://myportal/mysite/-/my-web-content-title/&lt;strong&gt;2.1&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;If I click on the URL, the detail page is showed with a default template for my Web Content and not with the custom template I've created for it.&lt;br&gt;But if I remove the version from the URL, my web content is rendered correctly with my template.&lt;br&gt;How to remove that version number from entry URLs?&lt;br&gt;I have to do it with &lt;a href="https://freemarker.apache.org/docs/ref_builtins_string.html"&gt;Freemarker string built-ins&lt;/a&gt;, or are there methods better than getURLViewInContext() to obtain my goal?&lt;br&gt;Thank you.&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Alessandro Candini</dc:creator>
    <dc:date>2019-10-28T16:25:40Z</dc:date>
  </entry>
</feed>
