Monday, November 30, 2015

Fetch content from multiple higher level of parent page when content in current page is empty.

temp.rightContent is fetching content of current page. Now check if this is empty we'll fetch from the parent page. This way we'll check again parent-parent i.e. grand parent page as so on. To achieve this i've take leveluid into count. We can apply different way as well. As per example below Typoscript object `lib.column_right_parent` is containing our required content.

temp.rightContent.current = CONTENT
temp.rightContent.current  {
  table = tt_content
  select.pidInList.data = leveluid : -1
  #select.pidInList.data = 1
  select.orderBy = sorting
  select.where = colPos= 2
  select.languageField = sys_language_uid
}

lib.column_right_parent < temp.rightContent.current
lib.column_right_parent.stdWrap.ifEmpty.cObject < temp.rightContent.current
lib.column_right_parent.stdWrap.ifEmpty.cObject {
  select.pidInList.data = leveluid : -2
  stdWrap.ifEmpty.cObject  < temp.rightContent.current
  stdWrap.ifEmpty.cObject {
    select.pidInList.data = leveluid : -3
    stdWrap.ifEmpty.cObject  < temp.rightContent.current
    stdWrap.ifEmpty.cObject {
      select.pidInList.data = leveluid : -4
        stdWrap.ifEmpty.cObject  < temp.rightContent.current
        stdWrap.ifEmpty.cObject {
          select.pidInList.data = leveluid : -5
      }
    }
  }
}

Typoscript to generate SELECT box (option-select) for page tree.

This typoscript below will generate a option select box for page tree or dropdown box for a page tree.
One simple javascript code has been added to make this select box active.
This example below is just an idea. We can easily customize this according to our need.

lib.field_menu_os = HMENU
lib.field_menu_os.entryLevel = 1
lib.field_menu_os {  
     wrap = <select id="menu_option_select" name="menu_option_select" size="1" onChange="javascript:_go_to_page(this.value);" >|</select>
     1 = TMENU
     1 {
       expAll = 1
       noBlur = 1
       NO {      
         stdWrap.dataWrap = <option value="{field:uid}">
         allWrap = |</option>
         doNotLinkIt = 1
       }
       # Inherit the 'allWrap' and 'doNotLinkIt' settings from the NO part
       CUR < .NO
       CUR = 1
       CUR {
         stdWrap.dataWrap = <option value="{field:uid}" selected="selected">
       }
     }
     2 = TMENU
     2 {
       expAll = 1
       noBlur = 1
       NO {
         stdWrap.dataWrap = <option value="{field:uid}">&nbsp;-&nbsp;
         allWrap = |</option>
         doNotLinkIt = 1
       }
       # Inherit the 'allWrap' and 'doNotLinkIt' settings from the NO part
       CUR < .NO
       CUR = 1
       CUR {
         stdWrap.dataWrap = <option value="{field:uid}" selected="selected">&nbsp;-&nbsp;
       }
     }
     3 = TMENU
     3 {
       expAll = 1
       noBlur = 1
       NO {
         stdWrap.dataWrap = <option value="{field:uid}">&nbsp;&nbsp;-&nbsp;&nbsp;
         allWrap = |</option>
         doNotLinkIt = 1
       }
       # Inherit the 'allWrap' and 'doNotLinkIt' settings from the NO part
       CUR < .NO
       CUR = 1
       CUR {
         stdWrap.dataWrap = <option value="{field:uid}" selected="selected">&nbsp;&nbsp;-&nbsp;&nbsp;
       }
     }    
  }

Simple one line of javascript will do the job easily. We can take help of jQuery too.
      function _go_to_page(selected_page_id){
  document.location.href='index.php?id='+selected_page_id;
 }