OpenCms "Tips and tricks"!

In this page we will see some "Tips and Tricks". We hope they will be useful for you!

How to check if a page is a detail page

How to check if a page is a detail page

  •  16 September 2020

When building lists of content, it's a typical requirement to link from a condensed view of the content to a more detailed view. For example, in a list of news, only title, teaser and maybe a date and author are displayed. You click on a news to get to a page showing the complete news article. Similarly, events, products or any other type of resource/content may be shown in a list with links to a detailed view added” (form https://documentation.opencms.org)

But how we can state programmatically if a page is a detail page?

We can use the class CmsJspStandardContextBean and the class method “isDetailRequest”, as for the following example:

 

CmsJspStandardContextBean contextBean = CmsJspStandardContextBean.getInstance( request );

if (contextBean.isDetailRequest() ) {

some_action;

}

else{

other_action;

}

The method can be useful if the same page shows both the list and the detail content.

In this case, my purpose could be to show a given content by using the above method.

  •  Tested on OpenCms 11.0.1

HTML editor

HTML editor

  •  05 July 2016

OpenCms uses the “HtmlWidget” widget to manage contents in HTML. The HTML editor is based on TinyMCE plugin.

In case you use the <i> tag, this tag will be replaced automatically by <em> tag, while the <b> tag will be replaced by <strong> tag.

For <i> tag this behaviour is annoying because the <i> tag is used in Bootstrap to display icons.

However you can use a workaround by modifying the “resources/editors/tinymce/jscripts/tinymce/tinymce.min.js” file; this is a file created on real file system when OpenCms is installed: you have to find the em/i string and delete it.

I know that the trick is a bit dirty (the best solution could be to generate a new custom module), but it's effective.

  •  Tested on OpenCms 9.5.2

How to render fonts having special extensions

How to render fonts having special extensions

  •  16 June 2016

If you have to manage fonts having special extensions (for example ttf, eot, woff), you can see that all runs right in offline project, but they are not rendered correctly in online project. To render them correctly you have to modify OpenCms configuration files.

The first step is to modify opencms-vfs.xml, to add the mimetype needed, for example font-woff:

<mimetypes>
      <mimetype extension=".ez" type="application/andrew-inset" />
       ...

<!-- New mimetype -->

<mimetype type="application/font-woff" extension=".woff"/>

<!-- end New mimetype -->

</mimetypes>

 The secon file you have to modify is opencms-importexport.xml, as in the following example:

<defaultsuffixes>

<suffix key=".jpg" />

...

<!-- New suffix -->

<suffix key=".woff"/>

<!-- end New suffix -->

</defaultsuffixes>

In order to the new configuration works you have to restart your application server (usually Tomcat).