Skip to main content
Home
Techies Briefcase
~ by Hari Venu

Main navigation

  • Home
  • About me
  • Photos
  • My Bookmarks

Breadcrumb

  1. Home
  2. Drupal 8, 9 and 10: Rendering Views Through Ajax

Drupal 8, 9 and 10: Rendering views through Ajax

By hari, 27 November, 2022

Sometime we required to render the views through ajax in your desirable place in you web page. Here is a views/ajax API snippet to call the views with some arguments and views details.

Create views

Create a views by using Views UI and Enable Use Ajax

Grab required parameter's values

Collect following parameters from Views UI

  • view_name like article_list
  • view_display_id like block_1/page_1
  • view_args like 1,2 (if you use Content ID in Contextual filters)

Add custom js into the Drupal module via *.libraries.yml

Refer if you don't know how to add libraries.yml - Adding assets (CSS, JS) to a Drupal module via *.libraries.yml

Add below snippet to custom_module/custom_module.libraries.yml

Add below content on custom_module/js/custom.js

Add library in target page by using hook_page_attachments

Add below snippet with your condition in custom_module/custom_module.module

Add div with id div-id in Drupal twig template or rendered element

Reference
  • https://pixelthis.gr/content/drupal-8-rendering-views-through-ajax
  • https://www.drupal.org/docs/creating-modules/adding-assets-css-js-to-a-drupal-module-via-librariesyml

Tags

  • Drupal
  • Ajax API
 

Topics

  • Composer
  • Commad Line Tools
  • JavaScript
  • Drupal
  • Solar Panel
  • Permission
  • Libraries
  • MySQL
  • Commad Line
  • RSA
  • VSCode
  • Windows
  • Entity Query API
  • Ubuntu
  • Bash Script
  • Drush
  • Bower
  • Errors
  • Workflow
  • File API
  • Docker
  • Linux
  • Lando
  • Articles
  • Views
  • Nginx
  • Twig
  • Multilingual
  • OOPs
  • Coder
  • Solar Power
  • PHP
  • Field API
  • Android
  • Cache
  • Webform
  • jQuery
  • phpcbf
  • Ajax API
  • Distribution
  • Drupal Behavior
  • Learning
  • kali
  • professional development
  • Neuron AI
  • Jellyfin
  • SSH
  • URL
  • Macbook
  • WSL2
  • Drupal AI
  • NPM
  • Git
  • Form API
  • phpcs
  • Drupal Console
  • Codesniffer
  • Moderation
  • PHPSeclib
  • Taxonomy
  • Mac OS
RSS Feed

Who am I !!!

Hari Venu V
harivenu.v1992@gmail.com
Mobile : +91 9895164181
Whatsapp : +91 9895164181
Linkedin
Drupal.org
Github

Document
Resume.pdf (114.38 KB)

Work !!!

Fulltime Developer @ QED42
hari.venu@qed42.com
Linkedin

Powered by Drupal & Maintained by Hari