CMS_INPUT_DOM - Listoutput without spanning 'p' tags

hoebbel
Crownpeak employee
Crownpeak employee
3 7 2,431

You can use lists within the CMS_INPUT_DOM component. Unfortunately these lists have to be defined within a section formattemplate, which puts unneeded tags within the output

<p>
    <ul>
        <li>...</li>
        <li>...</li>
    </ul>
</p>


To get rid of these unnecessary tags, you can put the following code within all of your section formattemplates and in the ul-formattemplate:

sectionformattemplate:

$CMS_IF(!#content.toString.trim.equals(""))$$CMS_SET(listLayer,0)$$CMS_SET(startTag,"<p>")$$CMS_SET(endTag,"</p>")$$CMS_SET(output,startTag + #content + endTag)$$CMS_VALUE(output.replaceAll(startTag+endTag,""))$$CMS_END_IF$


ul-formattemplate:

$CMS_IF(listLayer==0)$$CMS_VALUE(endTag)$$CMS_END_IF$$CMS_SET(listLayer,listLayer+1)$$CMS_IF(#list.style==2)$<ol>$CMS_VALUE(#content)$</ol>$CMS_ELSE$<ul>$CMS_VALUE(#content)$</ul>$CMS_END_IF$$CMS_SET(listLayer,listLayer-1)$$CMS_IF(listLayer==0)$$CMS_VALUE(startTag)$$CMS_END_IF$

Explanation:

$CMS_IF(!#content.toString.trim.equals(""))$ --> checks, if the section contains more then just white-spaces. Otherwise it will not be rendered.
$CMS_SET(listLayer,0)$ --> defines a counter to check, if the actual list is the outer list. Otherwise we do not need to eliminate the outer tags.
$CMS_SET(startTag,"<p>")$$CMS_SET(endTag,"</p>")$ --> definition of the tags which should be used for the appropriate section. You have to adjust the content 😉
$CMS_SET(output,startTag + #content + endTag)$$CMS_VALUE(output.replaceAll(startTag+endTag,""))$ --> Eliminates all empty (not needed) tags of the section formattemplate [in the example <p></p>]

Tested with FirstSpirit Version 4.2R2

7 Comments
rbitdd
Returning Responder

By using inline tables you have the same "problem" with spanning p-tags.

I edited my sectionformattemplate like written above and edited the table-template like this:

$CMS_VALUE(endTag)$<table>$CMS_VALUE(#content)$</table>$CMS_VALUE(startTag)$

Due to the fact that there are no nested tables possilbe you don't need to count the "listLayer" or here "tableLayer"

rbitdd
Returning Responder

If the first element in the dom is a list you get an ERROR "undefinded variable listLayer".

I changed my sectionformattemplate like this:

$CMS_SET(listLayer,0)$
$CMS_SET(startTag,"<p>")$
$CMS_SET(endTag,"</p>")$
$CMS_IF(!#content.toString.trim.equals(""))$
  $CMS_SET(output,startTag + #content + endTag)$
  $CMS_VALUE(output.replaceAll(startTag+endTag,""))$
$CMS_END_IF$

without newlines! Smiley Wink

rrichter
Occasional Collector

another example: if you use generic linktemplates to place floating pictures or boxes spanned with <div>-Tags into <p>-Tags, you will get a <p><div>...</div>...</p> construct that causes problems.

Place the linktemplate-code between $CMS_VALUE(endTag)$...$CMS_VALUE(startTag)$ and configure your <p>-Template as above mentioned and the problem will be solved.

Sebastian_N
I'm new here

If you like well formatted Sourcecode, use the $CMS_TRIM(level:4)$ - Option. After I formatted this code, I spend 2 houres to find this misstake :smileyconfused:.

But now it works perfect, thank you very much.

C_Klingbeil
I'm new here

Since 4.2.462.49171there is only one replacement of <p></p> in the beginning, but no replacement for the following <p></p> if there are multiple lists or a list containing another list. How can I fix that problem?

tomator
I'm new here

How does the code have to be changed to accomodate the fact that lists can be placed in inline-tables? Using the code as is would generate additional </p> and <p>-Tags inside the table cell, also in the wrong order (<td></p><ul>...</ul><p></td>).

Would extending the conditional placement of the end and start tag in the format-template "ul" to do so only if the list is not rendered in the format-template "table" be sufficient?

Peter_Jodeleit
Crownpeak employee
Crownpeak employee
Version history
Last update:
‎07-13-2010 05:43 AM
Updated by: