Zum Inhalt springen

Drupal 7 fields: Unterschied zwischen den Versionen

Aus Computech CMS Wiki
Simon Zeberli (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Simon Zeberli (Diskussion | Beiträge)
 
(12 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
==Fields für node.tpl.php==
==Fields für node.tpl.php==
http://api.drupal.org/api/drupal/modules!field!theme!field.tpl.php/7
http://api.drupal.org/api/drupal/modules!field!theme!field.tpl.php/7
Content
*Feldname
  <?php
**field.tpl.php
                hide($content['title']);
**field--field-type.tpl.php
                hide($content);    
**field--field-name.tpl.php
  ?>
**field--content-type.tpl.php
Caption
**field--field-name--content-type.tpl.php
  <?php
 
  print render($content['field_news_caption1']);  
* Content
  ?>
<syntaxhighlight lang="html4strict" line start="1" highlight="5" enclose="div">
Field
<?php
  <?php
  hide($content['title']);
  print render($content['field_address1']);  
  hide($content);
  ?>
?>
Title
</syntaxhighlight>
  <?php
 
  print render($content['title']);  
* Caption
  ?>
<syntaxhighlight lang="html4strict" line start="1" highlight="5" enclose="div">
Body
<?php print render($content['field_news_caption1']);?>
  <?php
</syntaxhighlight>
  print render($content['body']);  
 
  ?>
* Field
Images
<syntaxhighlight lang="html4strict" line start="1" highlight="5" enclose="div">
        <?php
<?php print render($content['field_address1']);?>
        $my_image = array(
</syntaxhighlight>
              'style_name' => 'thumbnail', //the image style created
 
                'path' => $node->field_flyin_portrait['und'][0]['uri'],
* Title
              );
<syntaxhighlight lang="html4strict" line start="1" highlight="5" enclose="div">
        print theme('image_style', $my_image); ?>
<?php print render($content['title']);?>
</syntaxhighlight>
 
* Body
<syntaxhighlight lang="html4strict" line start="1" highlight="5" enclose="div">
<?php print render($content['body']);?>
</syntaxhighlight>
 
* Images im Node anzeigen
<syntaxhighlight lang="html4strict" line start="1" highlight="5" enclose="div">
<?php
$my_image = array(
    'style_name' => 'thumbnail', //the image style created
      'path' => $node->field_flyin_portrait['und'][0]['uri'],
    );
print theme('image_style', $my_image);
?>
</syntaxhighlight>
 
==Fields Templete field--field_bilder.tpl.php==
==Fields Templete field--field_bilder.tpl.php==
Datei erstelln, wie das Field heisst. zB. field--field_fieldname.tpl.php das Beispliel ist für deine Bildergalerie gedacht.
Datei erstelln, wie das Field heisst. zB. field--field_fieldname.tpl.php das Beispliel ist für deine Bildergalerie gedacht.
  <?php
<syntaxhighlight lang="html4strict" line start="1" highlight="5" enclose="div">
     foreach ($items as $delta => $item) :
<?php
        print render($item);
foreach ($items as $delta => $item):
     endforeach;
     print render($item);
   ?>
endforeach;
?>
</syntaxhighlight>
 
Add Odd / Even  Class
<syntaxhighlight lang="html4strict" line start="1" highlight="5" enclose="div">
  foreach ($items as $delta => $item): ?>
      <div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?>"<?php print $item_attributes[$delta]; ?>><?php print render($item); ?></div>
     <?php endforeach; ?>
</syntaxhighlight>
 
==Datums Feld anpassen und berechnen==
<syntaxhighlight lang="html4strict" line start="1" highlight="5" enclose="div">
<?php
$days = format_date(strtotime($content['field_erledigt_bis']['#items'][0]['value']), 'custom', 'd.m.y');
$datum = strtotime(date("Y-m-d", strtotime($days)) . " -4 day");
  $dt = new DateTime("@$datum"); // convert UNIX timestamp to PHP DateTime
  echo $dt->format('d.m.Y'), " -4 Days"; // output = 2012-08-15 00:00:00
?>
</syntaxhighlight>
 
==Field in Block anzeigen==
* beim Nodetype eine fild erstellen
** Field Type = Bild
* Bild Stiel anpassen
* eine View erstellen welche als Block dargestellt wird.
** format = Felder
** unter Kontextfilter
*** Vorgabewert bereitstellen
*** Typ = Beitrags-ID Aus der URL
*** "Skip default argument for view URL" Hacken Setzen
Speichern und Fertig :D
==Fields für page.tpl.php==
<syntaxhighlight lang="html4strict" line start="1" highlight="5" enclose="div">
   <?php print render(field_view_field('node', $node, 'field_zitat', array('label'=>'hidden'))); ?>
 
</syntaxhighlight>
Field ohne Render Einfügen (zB. URL)
<syntaxhighlight lang="html4strict" line start="1" highlight="5" enclose="div">
<?php
$items = field_get_items('node', $node, 'field_link');
$first_item = array_shift($items);
$description = $first_item['value'];
print $description;
?>
</syntaxhighlight>

Aktuelle Version vom 6. August 2015, 12:42 Uhr

Fields für node.tpl.php

http://api.drupal.org/api/drupal/modules!field!theme!field.tpl.php/7

  • Feldname
    • field.tpl.php
    • field--field-type.tpl.php
    • field--field-name.tpl.php
    • field--content-type.tpl.php
    • field--field-name--content-type.tpl.php
  • Content
<?php
  hide($content['title']);
  hide($content);
?>
  • Caption
 <?php print render($content['field_news_caption1']);?>
  • Field
 <?php print render($content['field_address1']);?>
  • Title
<?php print render($content['title']);?>
  • Body
<?php print render($content['body']);?>
  • Images im Node anzeigen
<?php
$my_image = array(
    'style_name' => 'thumbnail', //the image style created
      'path' => $node->field_flyin_portrait['und'][0]['uri'],
    );
print theme('image_style', $my_image);
?>

Fields Templete field--field_bilder.tpl.php

Datei erstelln, wie das Field heisst. zB. field--field_fieldname.tpl.php das Beispliel ist für deine Bildergalerie gedacht.

<?php
foreach ($items as $delta => $item):
    print render($item);
endforeach;
?>

Add Odd / Even Class

  foreach ($items as $delta => $item): ?>
      <div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?>"<?php print $item_attributes[$delta]; ?>><?php print render($item); ?></div>
    <?php endforeach; ?>

Datums Feld anpassen und berechnen

<?php
$days = format_date(strtotime($content['field_erledigt_bis']['#items'][0]['value']), 'custom', 'd.m.y');
$datum = strtotime(date("Y-m-d", strtotime($days)) . " -4 day");
  $dt = new DateTime("@$datum"); // convert UNIX timestamp to PHP DateTime
  echo $dt->format('d.m.Y'), " -4 Days"; // output = 2012-08-15 00:00:00
?>

Field in Block anzeigen

  • beim Nodetype eine fild erstellen
    • Field Type = Bild
  • Bild Stiel anpassen
  • eine View erstellen welche als Block dargestellt wird.
    • format = Felder
    • unter Kontextfilter
      • Vorgabewert bereitstellen
      • Typ = Beitrags-ID Aus der URL
      • "Skip default argument for view URL" Hacken Setzen

Speichern und Fertig :D

Fields für page.tpl.php

   <?php print render(field_view_field('node', $node, 'field_zitat', array('label'=>'hidden'))); ?>

Field ohne Render Einfügen (zB. URL)

<?php
$items = field_get_items('node', $node, 'field_link');
$first_item = array_shift($items);
$description = $first_item['value'];
print $description; 
?>