logo

views in drupal 8

admin
01 Jun 2023

Follow these step to make block using views to show the related content according to category of the current content page.

Edit the views and open Advance section

  1. Add the  'Content: Has taxonomy term ID' in CONTEXTUAL FILTERS.
  2. Check 'Provide default value' option and then select the 'Taxonomy term ID from URL'.

 Step 1 Views create

3.     Check the 'Load default filter from node page, that's good for related taxonomy blocks' option.

4.     Check the 'Limit terms by vocabulary' option and the check the vocabulary.

Step 2

5.    Also, you need to create the "Content: ID" filter to exclude the current node from the view result.

Step 3

Select provide default value: Content ID from URL.
6.     Scroll down to the bottom of the window and click on the "More" link. In the more field-set check Exclude.

Step 6

 

admin
01 Mar 2021

If you want to create template for views page like page.tpl.twig so you follow these step. Whole page template for views page.

  1. Create copy of page.tpl.twig
  2. If your views url is ‘news-and-articles’ then rename file as ‘page--news_and_articles.html.twig’ and upload in your themes folder. If url has dash then replace dash with underscore.

After clear cache current template will work for this views instead of page.tpl.twig.

admin
22 Apr 2020

If you want to add if condition in my "global custom text" field in views Drupal 8

Example 1: Check node status and put conditional link according to publish status

{% if  status  %}
   put your HTML as condition
{% endif %}

Example 2: In this example we are checking a field value is empty or not. according to value in we are showing link or status

{% if  field_final_layout_date is empty %}

put your HTML as condition

{% else %}

Completed

{% endif %}

Example 3: In this example we are checking field value is empty or not with and operator

If field state and field city is not empty then print our output as your required

In else section you can put output as your required

{% if  field_state and  field_city  %}
	// Output
{% else %}
	// Output
{% endif %}

Example 4: Here we are checking city value and copare value as our required

If field city have value Delhi then print our output as required. You can check field machine name in replacement pattern

{% if field_city == "Delhi" %}
	// Output
{%endif%}