1
votes

New user of D8 : my problem is to access to fields in a view or even in general with Drupal 8. As we could do with ACF in Wordpress.

a {{ kint() }} crash my chrome but works with Firefox to explore the content var.

Unfortunately I do not managed to find and use fields' variables in my view.

I create a new view, which actually display the last three articles. These are well displayed in ugly list but I want to extract fields to put them in a custom html integration.

I create and use a new template for the view :

x node--view--liste-des-actualites--page-2.html.twig

In a custom parent :

x node--page-accueil.html.twig

But when I try to kint() content in my node--view--liste-des-actualites--page-2.html.twig, I have the custom field of the page (Page accueil) and can't find the article's one. I managed to do it in my custom page but not in this view.

{%
  set classes = [
    'node',
    'node--type-' ~ node.bundle|clean_class,
    node.isPromoted() ? 'node--promoted',
    node.isSticky() ? 'node--sticky',
    not node.isPublished() ? 'node--unpublished',
    view_mode ? 'node--view-mode-' ~ view_mode|clean_class,
    'clearfix',
  ]
%}
{{ attach_library('classy/node') }}
<article{{ attributes.addClass(classes) }}>
  <div{{ content_attributes.addClass('node__content', 'clearfix') }}>

    {{ content }}

    <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
        <a href="{{ LINK_VAR }}" class="bloc-type">
            <div class="categ categ_projet">{{ CATEGORY_VAR }}</div>
            <div class="img"> <img src="{{ IMAGESRC_VAR }}" alt=""> </div> 
            <span class="wrapper">
                <p class="date">{{ DATE_VAR }}</p>
                <h3>{{ TITLE_VAR }}</h3>
            </span> 
        </a>
    </div>

  </div>
</article>

EDIT I managed to guess some fields but this is definitely not a good way to find variables.. {{ node.label }} + {{ content.field_tags }} (But I do not want a rendered one, I just want the text/value)

1
what is your Q exactly? you want to know the variables of your fields inside your view to customize your content? - Gabbax0r
This is exactly that. Sorry I should add the exact Q to my post. "my problem is to access to fields in a view". - Paul Leclerc
do you use devel? - Gabbax0r
As I a write on my post I use kint() but I don't know why it's not always working. I think array are too big and make it crash. I can kint() little entity as content.field_tags but not content or content.field_image for example. Are you just using devel/dump/kint to reach your field variable ? - Paul Leclerc
i had the same problem with kint(); devel is a good workaround. in d7 there was a field "theme information" where you could see all fields in the view but sadly its still not ported to d8 - Gabbax0r

1 Answers

1
votes

if you use kint(); to debug large arrays can crash your browser. I would suggest to use the devel module https://www.drupal.org/project/devel. With devel you can debug your arrays inside of the Drupal8 UI for each content type, block or view.

In my case i use the UI of devel (additional tab on each content). in the module settings, you can chose how devel debugs, the error handling and the output.

As the OP commented it is possible to use a preprocess to display the array on your site:

function <themename>_preprocess_page(&$variables) { 
    dpm($variables);
 }