TMENU with External URLs

2008 January 1 | Filed in: Typoscript, TMENU, HMENU, typolink, Blog Christopher Torgalson

By default, TYPO3's menu objects render links to pages of the type "External URL" as links to pages within the site's domain. When clicked, these links redirect to the desired external location. Sometimes, it's desirable to override this behaviour and have the pages link directly to the external url instead. Fortunately, TYPO3's menu objects are quite flexible enough to make this possible.

In such a case, we can disable the default link rendering and use TMENU's .stdWrap object to render an entirely new link using the value of the URL field in the External URL page record.

  1. ### Create a menu where all pages of type "External URL" link directly to the actual external url:
  2. lib.blog.tmenu-external-url = HMENU
  3. lib.blog.tmenu-external-url {
  4.   1 = TMENU
  5.   1{
  6.     ### Remove 'onblur' attribute from links:
  7.     noBlur = 1
  8.     ### Wrap the resulting menu in an unordered list:
  9.     wrap = <ul>|</ul>
  10.     NO {
  11.       ### Do not link whatever output we generate here:
  12.       doNotLinkIt = 1
  13.       ### Wrap each menu item and its children in a list item:
  14.       wrapItemAndSub = <li>|</li>
  15.       ### Use a CASE cObject to build the menu links:
  16.       stdWrap.cObject = CASE
  17.       stdWrap.cObject {
  18.         ### Base the rendering on the value of the 'doktype' field in the page record; '3' is the External URL page type:
  19.         key.field = doktype
  20.         ### The default rendering:
  21.         default = HTML
  22.         default{
  23.           value {
  24.             ### Set the link text to the value of the title field in the page record:
  25.             field = title
  26.             typolink {
  27.               ### Set the parameter of the link to the uid field in the page record:
  28.               parameter.data = field:uid
  29.             }
  30.           }
  31.         }
  32.         ### The special rendering for the External URL page type:
  33.         ### Copy the default object into .3:
  34.         3 < .default
  35.         3{
  36.           value {
  37.             typolink {
  38.               parameter {
  39.                 ### Unset the value of .data:
  40.                 data >
  41.                 ### Set the parameter of the link to the value of the url field and prepend it with "http://":
  42.                 dataWrap = http://{field:url}
  43.               }
  44.             }
  45.           }
  46.         }
  47.       }
  48.     }
  49.   }
  50. }

TMENU with External URLs Download plain text version

The above code relies on the CASE cObject—much like a switch construct in PHP, the CASE cObject allows multiple alternate Typoscript outputs on the basis of some value. CASE is often a useful alternative to conditions or .if in TS.

Comments

No comments

Add comment

*
*
* required field

www.typo3apprentice.com
A Bedlam Hotel project © 2007—2010

Report a problem with this page

Bookmark and Share