Startseite
  • » Home
  • » Handbuch & FAQ
  • » Forum
  • » Übersetzungsserver
  • » Suche
Startseite › Forum › Drupalcenter.de › Module › Views ›

[gelöst] Field im Template abfragen

Eingetragen von Fidi (24)
am 28.02.2010 - 13:19 Uhr in
  • Views

Hallo!

In einer View habe ich unter Theme: Information ein field-Template integriert: views-view-field--frontpage-neu--type.tpl.php

Ich möchte je nach type (book, story ...) ein anderes Bild in der Tabelle anzeigen. Ich scheitere aber seit zwei Tagen an der Syntax von PHP (komme von ASP).

  • Wie spreche ich in einer einfachen If Abfrage das Feld Type an
  • Wie gebe ich ein Bild anstelle des Textes aus.

Trotz Suche in den Foren komme ich da nicht weiter.

ein Auszug aus dem Variablenarray. Mir geht es um node_type

stdClass::__set_state(array(
'nid' => '44',
'node_type' => 'book',
'node_title' => 'Buchseite',
'node_revisions_body' => 'idf oasi aopisd asadofi adsäisadäfisadöoisadfi sdaoäöisadf isadäf ',
'node_revisions_format' => '1',
'node_changed' => '1267111553',
'node_data_field_plz_field_plz_value' => NULL,
'node_vid' => '44',
'node_sticky' => '0',
'node_created' => '1267111553',
))

habt ihr einen Tipp für mich?

Schon mal Danke

Ingo

‹ [gelöst] CCK - Link wie übersetzten ? Ansichten Sortierkriterium Datum ›
  • Anmelden oder Registrieren um Kommentare zu schreiben

Grundsätzlich greifst du auf

Eingetragen von derjochenmeyer@... (591)
am 01.03.2010 - 10:19 Uhr

Grundsätzlich greifst du auf Elemente eines Objekts (stdClass) so zu:

<?php
$objekt
->element
?>

auf die Elemente eines Arrays so (Anführungszeichen sind wichtig):
<?php
$array
['element']
?>

Das kann man auch mischen, z. B.:

<?php
$node
->field_feldname['0']['value']
?>

Vielleicht hilft die Antwort schon weiter. Falls nicht, poste doch mal den Variablenarray, bzw das Objekt das du mit print_r() ausgegeben hast im Ganzen.

  • Anmelden oder Registrieren um Kommentare zu schreiben

Wenn Buch dann Bild

Eingetragen von Fidi (24)
am 01.03.2010 - 12:56 Uhr

Vielen Dank für die Hilfe.
Ich komme trotzdem noch nicht weiter.

Ich möchte sage: Wenn der type des Datensatzes ein book ist, dann gebe die Buchgrafik aus.
Soweit ich das verstehe, muss ich in der If Abfrage auf das Element node_type zugreifen und klären ob da book drinsteht.

In Anlehnung an deinem Beispiel habe ich folgendes ausprobiert.
If ($node->field_node_type['0']['value'] == 'book') {print $output;}
Es wird nichts ausgegeben.

Also konkret die Frage: Wie muss die If Abfrage aussehen, um zu schauen ob es ein Buch, Artikel, Foreneintrag oder sonstwas ist? (Ich denke, dass ich das dann noch in eine Case Verzweigung umsetzen muss. Aber erst einmal muss ich es verstehen.)

Ich wäre dir sehr dankbar, wenn du mir da weiterhelfen könntest.

Nutzt dir der folgende Array etwas (dsm(array_keys(get_defined_vars()));)?

... (Array, 15 elements)
0 (String, 13 characters ) template_file
1 (String, 9 characters ) variables
2 (String, 14 characters ) template_files
3 (String, 4 characters ) view
4 (String, 5 characters ) field
5 (String, 3 characters ) row
6 (String, 5 characters ) zebra
7 (String, 2 characters ) id
8 (String, 9 characters ) directory
9 (String, 8 characters ) is_admin
10 (String, 8 characters ) is_front
11 (String, 9 characters ) logged_in
12 (String, 12 characters ) db_is_active | (Callback) db_is_active();
13 (String, 4 characters ) user
14 (String, 6 characters ) output

Außerddem die Exportdatei des Views:

$view = new view;
$view->name = 'frontpage_neu';
$view->description = 'Emulates the default Drupal front page; you may set the default home page path to this view to make it your front page.';
$view->tag = 'default';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'type' => array(
'label' => 'Typ',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 0,
'exclude' => 0,
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'title' => array(
'label' => 'Titel',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'body' => array(
'label' => 'Textkörper',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 1,
'max_length' => '100',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'exclude' => 0,
'id' => 'body',
'table' => 'node_revisions',
'field' => 'body',
'relationship' => 'none',
),
'changed' => array(
'label' => 'Aktualisierungszeitpunkt',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'date_format' => 'small',
'custom_date_format' => '',
'exclude' => 0,
'id' => 'changed',
'table' => 'node',
'field' => 'changed',
'relationship' => 'none',
),
'field_plz_value' => array(
'label' => 'PLZ',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 0,
'label_type' => 'widget',
'format' => 'default',
'multiple' => array(
'group' => TRUE,
'multiple_number' => '',
'multiple_from' => '',
'multiple_reversed' => FALSE,
),
'exclude' => 0,
'id' => 'field_plz_value',
'table' => 'node_data_field_plz',
'field' => 'field_plz_value',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'sticky' => array(
'id' => 'sticky',
'table' => 'node',
'field' => 'sticky',
'order' => 'DESC',
),
'created' => array(
'id' => 'created',
'table' => 'node',
'field' => 'created',
'order' => 'DESC',
'relationship' => 'none',
'granularity' => 'second',
),
));
$handler->override_option('access', array(
'type' => 'none',
'role' => array(),
'perm' => '',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('header_format', '1');
$handler->override_option('footer_format', '1');
$handler->override_option('empty_format', '1');
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
'grouping' => '',
'override' => 1,
'sticky' => 0,
'order' => 'asc',
'columns' => array(
'type' => 'type',
'title' => 'title',
'body' => 'body',
'changed' => 'changed',
'field_plz_value' => 'field_plz_value',
),
'info' => array(
'type' => array(
'sortable' => 0,
'separator' => '',
),
'title' => array(
'sortable' => 0,
'separator' => '',
),
'body' => array(
'separator' => '',
),
'changed' => array(
'sortable' => 0,
'separator' => '',
),
'field_plz_value' => array(
'sortable' => 0,
'separator' => '',
),
),
'default' => '-1',
));
$handler = $view->new_display('page', 'Page', 'page');
$handler->override_option('path', 'dashboard');
$handler->override_option('menu', array(
'type' => 'normal',
'title' => 'Übersicht',
'description' => '',
'weight' => '0',
'name' => 'menu-menue',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
$handler = $view->new_display('feed', 'Feed', 'feed');
$handler->override_option('title', 'Newsfeed der Startseite');
$handler->override_option('style_plugin', 'rss');
$handler->override_option('style_options', array(
'mission_description' => 1,
'description' => '',
));
$handler->override_option('row_plugin', 'node_rss');
$handler->override_option('row_options', array(
'item_length' => 'default',
));
$handler->override_option('path', 'rss.xml');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
$handler->override_option('displays', array(
'default' => 'default',
'page' => 'page',
));
$handler->override_option('sitename_title', '1');

  • Anmelden oder Registrieren um Kommentare zu schreiben

Hi Fidi, die ganze

Eingetragen von derjochenmeyer@... (591)
am 01.03.2010 - 15:14 Uhr

Hi Fidi, die ganze Information nützt nichts :)

Es kommt drauf an in welcher datei du bist. Angenommen du bist in der node.tpl.php oder in der page.tpl.php dann wäre der zugriff so

<?php

if($node->type == 'book') {}
?>

Allerdings würde man den Code eher in der template.php einfügen. Z.B. der funktion template_preprocess_node() (Preprocess Funktionen siehe hier)

Du bist aber in einer Views-tpl.php Datei. Hier hast du folgenden Kommentar.

<?php
// $Id: views-view-field.tpl.php,v 1.1 2008/05/16 22:22:32 merlinofchaos Exp $
/**
  * This template is used to print a single field in a view. It is not
  * actually used in default Views, as this is registered as a theme
  * function which has better performance. For single overrides, the
  * template is perfectly okay.
  *
  * Variables available:
  * - $view: The view object
  * - $field: The field handler object that can process the input
  * - $row: The raw SQL result that can be used
  * - $output: The processed output that will normally be used.
  *
  * When fetching output from the $row, this construct should be used:
  * $data = $row->{$field->field_alias}
  *
  * The above will guarantee that you'll always get the correct data,
  * regardless of any changes in the aliasing that might happen if
  * the view is modified.
  */
?>

Deshalb würde hier ein

<?php
print_r
($row)
?>
aus der Datei erstmal Sinn machen. Eventuell muss du im View noch den Nodetype ausgeben, aber nicht anzeigen lassen. Dann kannst du bestimmt über $rowdrauf zugreifen.

  • Anmelden oder Registrieren um Kommentare zu schreiben

Bilder sind da!

Eingetragen von Fidi (24)
am 02.03.2010 - 10:14 Uhr

Hallo

Ich wollte in meiner View (Tabelle) Text gegen Bilder austauschen. Wenn der Eintrag eine Buchseite ist, soll vorweg ein Buch dastehen, wenn es ein Foreneintrag ist ....

Ich habe eine views-view-field.tpl.php Datei genommen, um sie entsprechend anzupassen.

Problem war: wie greife ich in einer Abfrage auf die relevanten Daten zu.
If ($output == 'Downloads') { .... }

hat geklappt, ist aber wohl nicht so sinnvoll.

Irgendwann Habe kam ich auf Folgendes:
if ($row->node_type == 'book') { ... }

Das war gut

Jetzt habe ich das vervollständigt:

switch ($row->node_type) {
    case 'book':
        echo "<img src='...../images/icons/lullacons_pack1/info.png' width='16' height='16' alt='Buchseite' />";
        break;
    case 'story':
        echo "<img src='......../images/icons/lullacons_pack1/large-alert.png' width='16' height='16' alt='Artikel' />";
        break;
case 'forum':
echo "<img src='...../images/icons/lullacons_pack1/large-stop.png' width='16' height='16' alt='Foreneintrag' />";
        break;
    case 'linkliste':
        echo "<img src='...../images/icons/lullacons_pack1/mini-comment.png' width='16' height='16' alt='Link' />";
        break;
case 'page':
        echo "<img src='...../images/icons/lullacons_pack1/user-option-remove.png' width='16' height='16' alt='Seite' />";
        break;
    case 'downloads':
        echo "<img src='..../images/icons/lullacons_pack1/user-multiple.png' width='16' height='16' alt='Download' />";
        break;
}

Das ist wahrscheinlich nicht perfekt, aber es funktioniert und ich bin zufrieden.

Vielen Dank Jochen! Ohne deine Hilfe hätte ich hier noch zwei Tage gesessen. Ich werde mich wohl doch um ein paar Grundlagen in PHP und Theming beschäftigen müssen.

Viele Grüße

  • Anmelden oder Registrieren um Kommentare zu schreiben

Benutzeranmeldung

  • Registrieren
  • Neues Passwort anfordern

Aktive Forenthemen

  • für drupal11 ein Slider Modul
  • [gelöst] W3CSS Paragraphs Views
  • Drupal 11 neu aufsetzen und Bereiche aus 10 importieren
  • Wie erlaubt man neuen Benutzern auf die Resetseite zugreifen zu dürfen.
  • [gelöst] Anzeigeformat Text mit Bild in einem Artikel, Drupal 11
  • Social Media Buttons um Insteragram erweitern
  • Nach Installation der neuesten D10-Version kein Zugriff auf Website
  • Composer nach Umzug
  • [gelöst] Taxonomie Begriffe zeigt nicht alle Nodes an
  • Drupal 11 + Experience Builder (Canvas) + Layout Builder
  • Welche KI verwendet ihr?
  • Update Manger läst sich nicht Installieren
Weiter

Neue Kommentare

  • melde mich mal wieder, da ich
    vor 1 Woche 5 Tagen
  • Hey danke
    vor 1 Woche 6 Tagen
  • Update: jetzt gibt's ein
    vor 1 Woche 6 Tagen
  • Hallo, im Prinzip habe ich
    vor 2 Wochen 4 Tagen
  • Da scheint die Terminologie
    vor 2 Wochen 4 Tagen
  • Kannst doch auch alles direkt
    vor 3 Wochen 1 Tag
  • In der entsprechenden View
    vor 3 Wochen 1 Tag
  • Dazu müsstest Du vermutlich
    vor 3 Wochen 1 Tag
  • gelöst
    vor 5 Wochen 5 Tagen
  • Ja natürlich. Dass ist etwas,
    vor 5 Wochen 6 Tagen

Statistik

Beiträge im Forum: 250233
Registrierte User: 20451

Neue User:

  • ByteScrapers
  • Mroppoofpaync
  • 4aficiona2

» Alle User anzeigen

User nach Punkten sortiert:
wla9461
stBorchert6003
quiptime4972
Tobias Bähr4019
bv3924
ronald3857
md3717
Thoor3678
Alexander Langer3416
Exterior2903
» User nach Punkten
Zur Zeit sind 0 User und 18 Gäste online.

Hauptmenü

  • » Home
  • » Handbuch & FAQ
  • » Forum
  • » Übersetzungsserver
  • » Suche

Quicklinks I

  • Infos
  • Drupal Showcase
  • Installation
  • Update
  • Forum
  • Team
  • Verhaltensregeln

Quicklinks II

  • Drupal Jobs
  • FAQ
  • Drupal-Kochbuch
  • Best Practice - Drupal Sites - Guidelines
  • Drupal How To's

Quicklinks III

  • Tipps & Tricks
  • Drupal Theme System
  • Theme Handbuch
  • Leitfaden zur Entwicklung von Modulen

RSS & Twitter

  • Drupal Planet deutsch
  • RSS Feed News
  • RSS Feed Planet
  • Twitter Drupalcenter
Drupalcenter Team | Impressum & Datenschutz | Kontakt
Angetrieben von Drupal | Drupal is a registered trademark of Dries Buytaert.
Drupal Initiative - Drupal Association