Using Nodejs to render html-css-javascript-images

i’m exploring and testing nodejs with a html, css and javascript. When i run index.html locally (no webserver) I can see the css,js,html,images render properly on my browser.

The problem when I create server.js and browse localhost:8000/index.html it just return my heading and paragraph…no nice images, css, js execute… I have gone through from SO and due to calling is only on html file but not css/js/images ….i dont know how to proceed further. I really appreciate advise from you guyz.

This is my server.js:-

var express = require('express'); var connect = require('connect'); var http = require('http');  var path = "";  var app = connect().use(express.static(__dirname + path)); http.createServer(app).listen(8000); 

This is my index.html:-

<!DOCTYPE html> <html> <head>     <title>TEST NODEJS WEB</title>     <!-- library -->     <link rel="stylesheet" href="/home/xero/next/css/next.min.css">     <script type="text/javascript" src="/home/xero/next/js/next.min.js">      </script>     <!-- Font Awesome -->     <link rel="stylesheet" href="/home/xero/next/font-      awesome/css/font-awesome.min.css"> </head> <body>     <div id="topology-container"></div>     <!-- Application scripts -->     <script type="text/javascript" src="topology_data.js"></script>     <script type="text/javascript" src="action-panel.js"></script>     <script type="text/javascript" src="topology.js"></script>     <script type="text/javascript" src="main.js"></script> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> 

This is folder structure in my machine:-

home   xero     next       js/next.min.js       css/next.min.css     myweb       index.html       topology_data.js       action-panel.js       topology.js       main.js       server.js 

When i browse index.html..only can see ‘My First Heading’ and ‘My first paragraph.’

Please help and advise me further. Thank you.

How to render all paragraphs of a node as slider instead among themselves?

Initial situation

I have a node type with a paragraph field. Each paragraph of the paragraph field is rendered among themselves.

What I want to achieve

  • The paragraph field inside the node should render all the paragraphs as a slick slideshow.
  • The node containing the paragraph field and all the paragraphs should also be part of a (second) slick slideshow (via a view filtered by the content type).

In short, the user will have finally a slideshow (with the single paragraphs) nested in a second slideshow (with the nodes).


The module slick views allows it to display the nodes of the node type as a slider. That’s fine to realize the node slider.

The module slick paragraph only allows to create slideshows as a paragraph type, but not rendering the paragraphs of a node themselves as part of a slideshow. They are still rendered among themselves inside the “node slider”.

So here i struggle a bit – any idea?

Thanks in advance, Phil

How to serialize a form’s render array to json in Drupal 8?

I want to build a REST resource to return Forms as JSON with all labels, help text, default values, etc…

When I use REST’s built-in resource /entity/entity_form_display/node.article.default it does not include the translated title, help text, autocomplete paths, or cardinality. Additionally i’m unsure if offering users the required administer node form display permission is a security issue.

UPDATE: I’ve finished a GET request built that flattens the Form definition to a simple array, but still hoping there’s a more Drupal-standard approach to this that understands the render arrays i’m parsing, better than I do.

public function get(String $  entity_type, String $  bundle_or_id) {      $  allowedTypes = array('comment'=>1,'node'=>1,'group'=>1,'group_content'=>1,'media'=>1,'user'=>1);     if (!isset($  allowedTypes[$  entity_type])) {       return $  this->returnError('invalid entity_type ' . htmlentities($  form_id));     }      if (is_numeric($  bundle_or_id)) {       $  node = \Drupal::entityTypeManager()->getStorage($  entity_type)->load($  bundle_or_id);       if (empty($  node)) {         return $  this->returnError('invalid entity id ' . htmlentities($  bundle_or_id));       }       $  account = \Drupal\user\Entity\User::load($  this->currentUser->id());       $  check = $  node->access('update', $  account);       if (!$  check) {         throw new AccessDeniedHttpException();       }     } else {       if (!$  this->currentUser->hasPermission('edit own' . $  bundle_or_id . ' content')) {         throw new AccessDeniedHttpException();       }       $  node = \Drupal::entityTypeManager()->getStorage($  entity_type)->create(['type' => $  bundle_or_id]);     }     $  form = \Drupal::service('entity.form_builder')->getForm($  node, 'default');      $  fields = \Drupal::service('entity_field.manager')->getFieldDefinitions($  entity_type, $  node->bundle());     $  attrs = array('#ajax', '#autocomplete_route_name', '#value', '#name', '#id', '#cols', '#input', '#options', '#errors', '#attributes', '#placeholder', '#rows', '#default_value', '#type', '#delta', '#required', '#title', 'target_id', 'cardinality', '#type', '#target_type');     $  defMethods = array('getLabel'=>'label', 'getDescription'=>'description', 'getType'=>'type', 'getTargetBundle'=>'bundle', 'getCardinality'=>'cardinality', 'getDefaultValueLiteral'=>'default_value', 'getSettings'=>'settings'); // , 'isMultiple'=>'is_multiple' , 'hasCustomStorage'=>'storage', 'getOptionsProivder'=>'options', 'getSchema'=>'schema'      $  inputs = array();     foreach ($  fields as $  field_name => $  field_definition) {       if (!isset($  form[$  field_name])) continue;       //if ($  field_definition->isBaseField() === false) continue; // errors out       $  field = $  form[$  field_name];       $  index = $  field['#weight'];        $  inputs[$  index] = array('field_name'=>$  field_name);       foreach($  defMethods as $  method=>$  label) {         $  val = call_user_func(array($  field_definition, $  method));         $  inputs[$  index][$  label] = ($  val instanceof \Drupal\Core\StringTranslation\TranslatableMarkup) ? (string)$  val : $  val;       }       if (isset($  field['#attributes'])) {         $  inputs[$  index]['#attributes'] = $  field['#attributes'];       }       if (!isset($  field['widget'])) {         foreach($  attrs as $  prop) {             if (isset($  field[$  prop]))               $  inputs[$  index][$  prop] = $  field[$  prop];         }         continue;       }       $  inputs[$  index]['widgets'] = array();       $  widgets = $  field['widget'];       $  count = 0;       foreach($  widgets as $  wi=>$  widget) {         if (!is_numeric($  wi)) continue;         $  value  = (isset($  widget['value'])) ? $  widget['value'] : $  widget['target_id'];         $  inputs[$  index]['widgets'][$  wi] = array();         foreach($  attrs as $  prop) {           if (isset($  val[$  prop])) {             $  inputs[$  index]['widgets'][$  wi][$  prop] = ($  value[$  prop] instanceof \Drupal\Core\StringTranslation\TranslatableMarkup) ? (string)$  value[$  prop] : $  value[$  prop];           }         }         if (empty($  inputs[$  index]['widgets'][$  wi])) unset($  inputs[$  index]['widgets'][$  wi]);         $  count++;       }       if (empty($  inputs[$  index]['widgets'])) unset($  inputs[$  index]['widgets']);       if (empty($  inputs[$  index]['cardinality'])) $  inputs[$  index]['cardinality'] = $  count;     }      return new JsonResponse($  inputs);   } 

Render Date Range on node template

I’m trying to render both start and end date on a node template in Drupal 8 from the Date range field from the content type. I’ve tried multiple ways to no avail.

— Only shows start date —

{{ kint(node.field_date_range.value ) }}   {% if node.field_date_range %} {{ node.field_date_range.value|date(format='l M j') }} {% endif %} 

Render array #theme vs #type

what is the different between the render array #theme and #type properties , because they both do the same thing with extra steps in the #type property :

  • #theme: invoke HOOK_theme implementation in all modules,then call a registered theme implementation that match the #theme value ,which will render the HTML using the template file(or theme_[theme_name] function if template key is not set) , and pass to it the render array through the render element , to use a specific logic to render it into HTML.

  • #type: do the same but starts form HOOK_element_info()

so if they are the same when to use each one ?

How can I render HTML tags in a variable in a twig template?

I have a variable in my twig template called description.
The variable is a string with an html em tag in it. When I go to the webpage to view the field, the html em tags are stripped out of the string.
I am on a Drupal 8 site and my variable was rendered through
\Drupal::service('renderer')->render() The twig autoescape parameter is set to false.

Using the twig debugger, I can see that my markup object includes the html em tags so I know that the problem is how twig is processing the string.
I’ve read in other posts to use the |raw tag but this has no effect.
What can I do to make the HTML in my twig variable render properly?

Update: I’ve included a screenshot of my output from {{ dump(description) }} enter image description here

React JSON правильно вернуть Render

Суть такая: По ссылке тягаю через JSON API с инстаграмма картинки.

import React from 'react';   const App = () => {     var requestURL = '';      var request = new XMLHttpRequest();'GET', requestURL);     request.responseType = 'json';     request.send();     request.onload = function () {         request.response['graphql']['shortcode_media']['edge_sidecar_to_children']['edges'].map((name) =>             //<img src={name['node']['display_url']}/>             console.log(name['node']['display_url'])         )     };      return (         <p>{request.response}</p>         )     };  export default App; 

Если я помещаю

return (     request.response['graphql']['shortcode_media']['edge_sidecar_to_children']['edges'].map((name) =>         <img src={name['node']['display_url']}/>     ) ) 

внуть onload, то появляется ошибка, что ничего не позвращает render…

А в данном случае <p>{request.response}</p> пустой. А если пытаться вывести картинки вне onload, то request.response – пустой…

Внутри onload если делать console.log, то все ссылки выбираются… Что я делаю не так???

How do I render a tag?

I am using the following code.

public function buildForm(array $  form, FormStateInterface $  form_state) {  $  appDir = take_control_app_dir();  $  extpath = take_control_fb_ext_client_path();   $  validationString = take_control_random_string(20);  $  fbpath = take_control_client_path(drupal_get_path('module', 'fb') . '/fb.html?extpath=' . $  extpath);  $  form = [    'example one' => [      '#markup' => '<iframe src=""></iframe>'    ],    'take_control' => [      '#markup' => '<p>iframe</p>',         ],  ];   return $  form; } 

The <iframe> tag is not rendered.

Is there any way to make it render?

Render a users Lync status in a display template

I’m trying to render the author field in a custom display template to show the Lync presence icon.

I would like to get a result similar to this template that displays the presence and the name. But i’m fairly new to display templates, and very new to JavaScript so i don’t really know where to look and after what.

enter image description here

I was looking through some different OOTB templates and stumbled over the one called Common Hover Panel Body and there seem to be some JavaScript doing the work in there but i’m unsure what to extract. Has anyone done this before?

Does Unearthed Arcana render Favored Souls redundant?

In Unearthed Arcana, there is a set of optional rules for Spontaneous Divine Casters. Under the assumption that these rules are used and that any Favored Soul fluff is ignored, is there any mechanical reason to play a Favored Soul instead of a Spontaneous Divine Caster Cleric? After all, the Favored Soul lacks some fantastic Cleric abilities like Turn Undead.