Elemente des Mastertemplates bedingt zur Auswahl anbieten

Dieser Artikel beschreibt, wie Sie Elemente des Mastertemplates bei der Elementauswahl in der Seitenbearbeitung nur bedingt zur Auswahl stellen.

Innerhalb des Mastertemplates können Sie über das WSL-Tag "wslMastertemplate:php" PHP-Abfragen vornehmen. So können Sie z.B. über PHP einen Abfrage auf den Pfad der in Bearbeitung befindlichen Datei vornehmen, um sprachabhängige Strukturelemente anzubieten. Dies wird nachfolgend als Beispiel angeführt.
Denkbar sind hier auch andere Abfragen, wie z.B. bestimmte Verzeichnisbereiche, etc.

Beispiel: Auszug aus der headline.text.wItemMastertemplate.php mit Abfrage auf bestimmte Zeichenfolge (z.B. -de)

...
  <wd:group>
  
  <wslMastertemplate:php>
     if(preg_match("/-de/", wEnv::getGlobalValue('wEditorPath'))){
  </wslMastertemplate:php>
    <wd:item name="Überschrift" en:name="Headline" icon="/[IHR-LAYOUT-PROJEKT]/wGlobal/layout/images/element-icons/element_headline.gif" type="headline.text">
      <wd:fragment id="title" type="char.text"/>
      <wd:fragment id="display" type="char.display"/>
      <wd:fragment id="text" type="text.standard"><![CDATA[Überschrift]]></wd:fragment>
      <wd:fragment id="layout" type="char.default">0</wd:fragment>      
    </wd:item>
    <wslMastertemplate:php>
    }
  </wslMastertemplate:php>
  <wslMastertemplate:php>
     if(preg_match("/-en/", wEnv::getGlobalValue('wEditorPath'))){
  </wslMastertemplate:php>
    <wd:item name="Überschrift" en:name="Headline" icon="/[IHR-LAYOUT-PROJEKT]/wGlobal/layout/images/element-icons/element_headline.gif" type="headline.text">
      <wd:fragment id="title" type="char.text"/>
      <wd:fragment id="display" type="char.display"/>
      <wd:fragment id="text" type="text.standard"><![CDATA[Headline]]></wd:fragment>
      <wd:fragment id="layout" type="char.default">0</wd:fragment>      
    </wd:item>
    <wslMastertemplate:php>
    }
  </wslMastertemplate:php>
  </wd:group>
...

Beispiel: Auszug aus der formular.elements.wItemMastertemplate.php mit Abfrage auf den Benutzertyp (z.B. admin oder standard)

...
  <wd:group>
    ...
    <wslMastertemplate:php>
       if(wUserCur::getType() == 'admin'){
    </wslMastertemplate:php>    
    <wd:item name="Spambot-Falle (Honeypot)" en:name="Captcha (spam protection)" icon="/[IHR-LAYOUT-PROJEKT]/wGlobal/layout/images/element-icons/element_honeypot.gif" type="formular.element.honeypot" uid="6c7bf4796a13457c1a43d90bdff505d6">
      <wd:fragment id="name" type="char.text">dyn-subject-of-request</wd:fragment>
      <wd:fragment id="label" type="char.text">Bitte nicht ausfüllen</wd:fragment>
      <wd:fragment id="style" type="char.text"/>
      <wd:fragment id="class" type="char.text"/>
      <wd:fragment id="display" type="char.default"/>
      <wd:fragment id="errorMessage" type="char.default">Bitte lassen Sie das letzte Feld leer!</wd:fragment>
    </wd:item>
    <wd:item name="Spamschutz (Captcha)" en:name="Captcha (spam protection)" icon="/[IHR-LAYOUT-PROJEKT]/wGlobal/layout/images/element-icons/element_captcha.gif" type="formular.element.captcha" uid="59b07f673bdce30dbed4dd1406c1d3a6">
      <wd:fragment id="name" type="char.text">captchaInput</wd:fragment>
      <wd:fragment id="icon" type="char.text"/>
      <wd:fragment id="label" type="char.text">Sicherheitsabfrage</wd:fragment>
      <wd:fragment id="text" type="char.text">Bitte geben Sie den Wert, den Sie auf dem Bild sehen, in das Feld ein.</wd:fragment>
      <wd:fragment id="errorMessage" type="char.text">Der eingegebene Wert stimmt nicht mit dem auf dem Bild überein.</wd:fragment>
      <wd:fragment id="quality" type="char.text">10</wd:fragment>
      <wd:fragment id="style" type="char.text"/>
      <wd:fragment id="class" type="char.text"/>
    <wd:fragment id="display" type="char.default"/><wd:fragment id="backgroundColor" type="char.default"/></wd:item>
    <wslMastertemplate:php>
       }
    </wslMastertemplate:php>
...