1

I have a view which shows nodes of 3 specific content types. The content shown is coming from the parent node with entity reference fields where the nodes can be selected to be shown in the view.

I was wondering how I could add custom content, or maybe a node to the end of a that view without having to select it on the parent, because this is always the same content.

What I want is like have the view display a node or some programmatically custom content. It should be there as last page. For example I have a view with 4 nodes, the pager should show 5 and have the 5th page be the node/content I want. I don't want to have to add it every time on the parent node with the entity reference field. It should be there by default.

2

Probably the easiest way to do this would be to add a footer to your view. If you are on the admin screen for your view, you should see options for Page Settings, Header, and Footer in the middle column.

View admin screen showing where to add content to footer region

If you "Add" content to the Footer area it will always output below your view content. There are several options including to display a rendered node.

1
  • Thank you for your reply! This could be a solution. This is not exactly what i want, what i want is like have the view display a node or some programatticaly custom content. It should be there as last page. For example i have a view with 4 nodes, the pager should show 5 and have the 5th item be the node/content i want. I dont want to have to add it every time on the parent node with the entity reference field. It should be there by default. – Skywalker May 27 '18 at 15:44
0

You can achieve this by creating your own views template file in themes/custom/MYTHEME_NAME/templates. See this documentation for naming conventions https://api.drupal.org/api/drupal/core%21modules%21views%21views.theme.inc/group/views_templates/8.6.x

In my case, I am using the Views Bootstrap Module and wanted to change the template of a view which uses the Bootstrap Grid mode. So I copied views-bootstrap-grid.html.twig from the module's directory (/modules/contrib/views_bootstrap/templates) into my theme's template directory and renamed it to views-bootstrap-grid--companies--block.html.twig

Inside the template file, I added the needed html code:

{#
/**
 * @file views-bootstrap-grid.html.twig
 * Default simple view template to display Bootstrap Grids.
 *
 *
 * - columns: Contains rows grouped by columns.
 * - rows: Contains a nested array of rows. Each row contains an array of
 *   columns.
 * - column_type: Contains a number (default Bootstrap grid system column type).
 *
 * @ingroup views_templates
 */
#}
{%
  set classes = [
    'views-view-grid',
  ]
%}
{% if title %}
  <h3>{{ title }}</h3>
{% endif %}
<div id="{{ id }}" {{ attributes.addClass(classes) }}>
  <div class="row">
    {% for row in rows %}
      <div {{ row_attributes.addClass(options.row_class) }}>
        {{ row }}
      </div>
    {% endfor %}
    <div class="my_custom_text">
        MY CUSTOM TEXT
    </div>
  </div>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.