I want to add different css styles to my edit/create pages. The easiest way I can think to do that would be to add 'edit/create' classes to the body tag when the node is being edited or created by adding them to html.html.twig. hook_node_access() has the variable $op which defines the current operation, so the question is how do I expose that variable to my html.html.twig template so I can add the classes only when update/create?
115241
I'm trying to add a custom CSS class to the &lt;body&gt; tag, How can I modify or pre-process the &lt;body&gt; tag to add the class body, Is it right to style the &lt;body&gt; tag with css file?
7928
I wanted to add custom JavaScript code on certain nodes. I have written this code in the html.tpl.php template, but this doesn't work. (donate is the path alias for a node.) &lt;?php if(arg(0) == 'DONATE'): ?&gt;   &lt;script&gt;     (function() {       // ...     );   &lt;/script&gt; &lt;?php endif; ?&gt;
25980
suggested to have templates for tags. Their example was with the  tag on Stack Overflow.  I'm suggesting a more general approach:  Templates, Mark II  I suggest that each site will have a template. That template will prefill the  textbox when a new question is asked. However, it will be completely optional.  Something like (for Stack Overflow):  ## The Problem ## { Please tell us what the problem is with as many details as possible.   Include language, operating system, and any other relevant information.   Remember to add the relevant tags below, too. } ## Attempted Solutions ## { Please tell us what you've tried so far. Have you tried searching Google?    What queries? } ## Existing Code ## { Do you have any existing code to show? Please keep it short and simple.    We should be able to detect the problem right away. }   Why am I suggesting this?  Well, it seems as though most users will stick with the default. They don't bother to read, and so prefilling the question form for them with information that we know might be relevant, will forceWe'll get to that in a second them to actually stop and read.  Scenarios:   Best case: User arrives to ask a question, actually reads the template, fills the correct information in the placeholders. (Yeah, because that'll happen a lot) Neutral: User simply removes all of the template text and rewrites their own question. Result is exact same as we have currently. Worst case: User will ignore or misunderstand the template, will use it wrong or not at all and we'll get something like  &lt;template text here, still unfilled&gt; &lt;(crappy) question&gt;   This can be solved in a couple different ways. We could detect the template tags (i.e. { }, subject to discussion), and throw an error when a user attempts to post with them still available. We could also act more autonomously and remove placeholders which still exist.    Some more points:   Templates should be per-site, not per-tag. Sure, there are differences between the tags, but all questions are expected to have the same general information, and this isn't meant to be a rule, but a guideline to help write better questions. Site templates should be editable by that site's mods, like close reasons. We could autofocus on the first placeholder, and perhaps implement TAB to jump from one placeholder to the other, similar to mixins in IDEs. This doesn't have to be implemented everywhere. This suggestion makes sense to Stack Overflow or Superuser, but not to Anime &amp; Manga or Gaming All of the details are subject to discussion, and all discussion is welcomed.
10956
I am looking to modify the default output of Drupal 8 of links in a certain situation, the language switcher. Ideally I want to be able to do that in a twig template and not have to produce a  that overwwrites that whole link generation system and add a BIG if for the cases I need to overwrite.  I think the output layout should be controllable in the twig template similar to  (this answer outputs the same url for every languages)  I am using bootstrap as a base theme so i'd like to use the bootstrap markup for my links (btn btn-primary, dropdown)  Here is my code I am trying to make links--language-block.html.twig  {%- if links|length == 2 -%}     {# show only alternate language button #}     {%- for key, item in links -%}         {%- if not item.attributes['#options']['set_active_class'] -%} {# &lt;--- this is always true!? #}             &lt;a href="{{ item.link['#url'] }}" class="btn btn-primary"&gt;{{ item.link['#title'] }}&lt;/a&gt; {# #url is always the same what ever the language it is pointing to! #}         {%- endif -%}     {%- endfor -%} {%- elseif links|length &gt; 2  -%}     {# show selected language in button and other languages in drop down #}     &lt;button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown"&gt;{{ selectedLanguage }}&lt;span class="caret"&gt;&lt;/span&gt;&lt;/button&gt;     &lt;ul class="dropdown-menu"&gt;         {% for key, item in links %}             {%- if not item.attributes['#options']['set_active_class'] -%} {# &lt;--- this is always true!? #}             &lt;li&gt;&lt;a href="{{ item.link['#url'] }}"&gt;{{ item.link['#title'] }}&lt;/a&gt;&lt;/li&gt;             {% endif %}         {% endfor %}     &lt;/ul&gt; {%- endif -%}   Anyone has an idea on how to do this?
94510
How can I customize the default search block form template, I now use below template to display a search form block, but this code doesn't allow me to edit and customize each part of this form separately and doesn't have any flexibility.  form--search-block-form.html.twig  &lt;form{{ attributes.addClass('search-form', 'search-block-form') }}&gt;   {{ children }} &lt;/form&gt;   and then print in my theme by below code:  {{ page.search_box }}   Is there any better template name suggestion with more variables and flexibility in customization?
46240
I am developing a WP theme with MVC approach. It only have index.php, functions.php and styles.css on the parent directory. So, I do not want to place page templates on it rather then I want to programmatically provide them from View classes while functionality from edit screen stays the same.   Users need to have page templates select option on the edit screen. How do I successfully add Items to the template dropdown?  I tried to hook into  filter.   Example code:  add_filter( 'theme_page_templates', function($templates){      $templates['my-page-template.php'] = "My Page Template";      return $templates;  });   This does not work because of the use of  on the filtered array, which removes the added page template item. I don't understand why this function is used. It seems you can only remove page template from the list but can not add a new one using the given filter.  Is there any other way around?
56577
In my Drupal7, I have same piece of code in tpl.php files for two different nodes. My tpl.php files are following:  page--node--9.tpl.php page--node--11.tpl.php   Since code is same for both pages, it is possible to create a tpl.php file for both nodes? I mean something like   page--node--9and11.tpl.php
114452
I am trying to add JavaScript and CSS files to one node type page from my template.php file but it is not working.  Here is my template.php code:   &lt;?php // $Id: template.php,v 1.13 2010/12/14 01:04:27 dries Exp $  function mttheme_preprocess_html(&amp;$variables) {   $node = node_load(arg(1));   if ($node-&gt;type = 'sales_team_page') {     drupal_add_css('misc/jquery.fancybox-1.3.4.css');     drupal_add_js('misc/jquery.mousewheel-3.0.4.pack.js',       array('type' =&gt; 'file', 'scope' =&gt; 'header')     );     drupal_add_js('misc/jquery.fancybox-1.3.4.pack.js',       array('type' =&gt; 'file', 'scope' =&gt; 'header')     );     drupal_add_js('misc/jquery.fancybox-calls.js',       array('type' =&gt; 'file', 'scope' =&gt; 'header')     );   } }   Does anyone know why it is not working?
71354
I have edited a script that creates some nodes, but the only problem is, it always created a new material. I want it to either add the nodes on the existing material, or a pre-defined material. Here is the script base I am using.    Thanks for the help in advance! :D
42003
For theming reasons I'd like to add a specific class at the "block" level to some of the blocks I'm generating with a custom module. I know there is a module , but I would rather like to do it directly in code (there is no need to change is afterwards).   I also know of , but that does not seem to allow adding or editing classes.  Is it possible to add a class with to a block from within my module code? I'm using Drupal 7.
85664
Is it possible to add a node reference field using the  module?  If it is, how can I add it in my webform?
101885
I would like to add a custom  to  the &lt;body&gt; tag. I am using Drupal 7/Corolla.  How can I do it programmatically from my custom module?
38508
In Drupal 7 the current language is a global variable we can access with   global $language; $langcode = $language-&gt;language;    I want to know how can we access the current language in a Twig file in Drupal 8 (in page--front.html.twig for example)?
58950
In views I can add PHP snippets for custom validation or when I want to provide default value for contextual filter. It is telling me that I can use $view or $argument - but where is documentation of these objects? Where can I read what are my possibilities in these areas (or how check this, by using debugger for example)?
46370
I am trying to add a body class to my site in template.php based on whether or not a node is published or not. I had a look around here and on drupal.org and pieced together some code but I am getting an error. Here is what I have tried so far:  function responsive_process_html(&amp;$variables) {    if ($node-&gt;status == 1){         //$variables['#attributes']['class'][] = 'pub';         $variables['classes_array'][] = 'published';     }      else {         $variables['classes_array'][] = 'not-published';     } }   ... but I am getting this error:  Notice: Undefined variable: node in responsive_process_html() (line 37 of /sites/all/themes/responsive/template.php). Notice: Trying to get property of non-object in responsive_process_html() (line 37 of /sites/all/themes/responsive/template.php).   I also tried $variables['#attributes']['class'][] = 'published'; instead of $variables['classes_array'][] = 'published'; but it made no difference.
95023
In Drupal 7 I frequently use node_view() for rendering nodes (using view modes) in blocks or pages as follows:  $nids = array(123,456,789); $nodes = node_load_multiple($nids); foreach ($nodes as $node) {   $node_view = node_view($node, 'teaser');   $output .= drupal_render($node_view); } $build['nodes']['#markup'] = $output; return $build;   node_view()/entity_view() has been deprecated and replaced by a view builder as explained in change record . The information is not detailed enough for me to be able to figure out how to achieve the same result.  How can you render nodes in Drupal 8 so that the output can be used in the render array of a block or page?
19350
I create a view (FO) that lists certain content type. By default, I put a pager (mini) and a number of items per page (content 10 per page).  This view, I integrated into a content type (CFTO) in addition to other parameters. If I agree, I want to use my other variables to redefine this view without saving it in a database (eg disable the pager / display 3 content page / ...)  I try different hooks as hook_views_pre_view, hook_views_pre_render, views_pre_build, but nothing works. I can not change the number of a content page. This is my different test :   I wish i could change my view different information as enable / disable pager and more then change the number of elements of the page.  I find a way of hook_views_pre_render(&amp;$views) to change the pager and more. It works well.  function my_views_pre_render(&amp;$view){ //For more $view-&gt;display['page']-&gt;handler-&gt;options['use_more'] = TRUE;  //For pager if(!$this_node_pager_value) {     $view-&gt;query-&gt;pager-&gt;set_items_per_page($view-&gt;total_rows);     $view-&gt;query-&gt;pager-&gt;update_page_info(); }}   Now i wish i could change the number of elements in my page to display, I tested this code in different hook sities previously.  function my_views_pre_render(&amp;$view){ if($this_node_pager_value) { //TEST 1 $view-&gt;query-&gt;pager-&gt;set_items_per_page(3); $view-&gt;query-&gt;pager-&gt;update_page_info();  //TEST 2 $view-&gt;exposed_raw_input['items_per_page'] = 3; }}  function my_views_pre_view(&amp;$view, &amp;$display_id, &amp;$args){ //TEST 1 $view-&gt;display_handler-&gt;display-&gt;display_options['pager']['options']['items_per_page'] = 3;  //TEST 2 $view-&gt;query-&gt;pager-&gt;set_items_per_page(3); $view-&gt;query-&gt;pager-&gt;update_page_info();  //TEST 3 $view-&gt;exposed_raw_input['items_per_page'] = 3;  }  function my_views_pre_execute(&amp;$view){ //TEST 1 $view-&gt;display_handler-&gt;display-&gt;display_options['pager']['options']['items_per_page'] = 3; //TEST 2 $view-&gt;query-&gt;pager-&gt;set_items_per_page(3); $view-&gt;query-&gt;pager-&gt;update_page_info(); //TEST 3 $view-&gt;exposed_raw_input['items_per_page'] = 3; //TEST 4 $view-&gt;display_handler-&gt;set_option('items_per_page', 3); }   function cci_generic_views_pre_build(&amp;$view){ //TEST 1 $view-&gt;pager["items_per_page"] = 3; //TEST 2 $view-&gt;display_handler-&gt;options['pager']['options']['items_per_page'] = 2; //TEST 3 $view-&gt;display_handler-&gt;options['pager']['options']['expose']['items_per_page'] = 2; }   None works. Would you know what should be done to make it work?  You would know what is the right hook to use? And how to change this value? thank you for your help   Djik