How to obtain shorty ID manually

20 views
Skip to first unread message

Andrew Hardy

unread,
Oct 9, 2018, 8:41:04 AM10/9/18
to dotCMS User Group
I have read the page about the shorty ID, which I think need if I am going to easily size my images, but I cannot understand how to get it.  I see what looks like some velocity that will enable me to obtain it but I do not know where I can just run that velocity just for the purposes of getting the shorty id.  Everywhere I try to put it into a page simply messes up the page.

eg

<header id="header" class="header-wrap">
#set($content = $dotcontent.find(“f29effee-9bab-44cb-8b19-399cbb4a08ed”))
...

...src="Da/$content.shorty/     ...

etc etc.

Can I just get the shorty id from somewhere some how rather than putting this velocity into the html?

OR... what are the rules for where you can place a #set for example?

Andrew Hardy

unread,
Oct 9, 2018, 12:28:36 PM10/9/18
to dotCMS User Group
I see now the short id is simply just the first 10 digits of the id.  The page I was reading talking about File Asset Pathing with Shorty ID did not seem to mention this.

jonathan...@dotcms.com

unread,
Oct 11, 2018, 1:28:18 AM10/11/18
to dotCMS User Group
I think you may do something like:

```
package com.dotcms.rendering.velocity.viewtools;

import com.dotcms.uuid.shorty.ShortyIdAPI;
import com.dotmarketing.business.APILocator;
import org.apache.velocity.tools.view.context.ViewContext;
import org.apache.velocity.tools.view.tools.ViewTool;

public class ShortyIdWebAPI implements ViewTool {

private ShortyIdAPI shortyIdAPI = APILocator.getShortyAPI();


public void init(Object obj) {
ViewContext context = (ViewContext) obj;
}

public String getShorty (final String identifier) {

return this.shortyIdAPI.shortify(identifier);
}
}

<tool>
<key>shorty</key>
<scope>request</scope>
<class>com.dotcms.rendering.velocity.viewtools. ShortyIdWebAPI </class>
</tool>


 = $shorty.getShorty($identifier);
```
Reply all
Reply to author
Forward
0 new messages