In a custom module I'm adding a custom page template suggestion per multi-site like following which would then search for page--MYSITE.html.twig in the current theme's /templates folder.  /**  * Implements hook_theme_suggestions_HOOK_alter().  */ function MYMODULE_theme_suggestions_page_alter(array &amp;$suggestions, array $variables) {    $site_path = \Drupal::service('site.path');   $site_path = explode('/', $site_path);   $site_name = $site_path[1];    $suggestions[] = 'page__' . $site_name; }   Question: Is it possible to also specify a new location for this template. Like let's say inside my custom module's /templates folder?  Why: It would let me use a core theme but with my custom template (without the need to add something custom to core or to create a new sub-theme, lazy as I am).  There are 3 suggestion hooks that come into my mind but with none if them it seems possible to also specify a custom location. Is this right? Or is there a way? Is it bad practice to do so?
123057
I am using hook_theme_suggestions_HOOK() to implement a custom template file in my drupal 8 website like below.   /**  * Implements hook_theme_suggestions_HOOK().  */ function mymodule_theme_suggestions_page(array $variables) {   $template_suggestions = array();   // This is used to display only $content.   if (isset($_GET['ajax']) &amp;&amp; $_GET['ajax'] == 1) {     $template_suggestions[] = 'page__ajax';   }   return $template_suggestions; }   Above code is working fine and I can add template page--ajax.html.twig inside my current active theme and changes in template is reflecting in page.  But when I put that file inside my module itself file is not detecting and changes not reflecting in page and taking default page.html.twg template file.  How can I provide default template file within my module itself?
99354
I want to add the following code in my  section of the front page using a Drupal 8 sub theme of Bartik.   Can anybody help how to do it? What is the best way to do it in this new twig version of theme? Where is page.tpl?  &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="stepcarousel.js"&gt;&lt;/script&gt;
6577
I previously asked this  about modifying the default user registration form. The default form is largely fine, I just want to add some text and some links above and below the form (i.e. instructional advice etc).  One of the answers to my previous question suggested creating a module with the hook form_alter. I did this, however, it seemed all that achieved was adding adding new text fields to the form. I don't want to add new text fields, just some additional text/html before and after the form.  Is there any way to do this with form_alter, and if so, could you detail the code I'd need to do this (such that is does not add another user visible field)?  If there's another way to modify the page directly (not just the form) could you detail it? Keep in mind I want this to work with all themes, so when I change themes my changes do not disappear (which is why I was hoping to be able to do it in a module).
109900
I'm building a module (my_module) in Drupal 7. It has some functionality and also will create a new content type. In my_module.install, I implemented hook_install() (my_module_install()).    Can I use more hook_install() to create a new content type (my_module_install()) in this module? If the answer is yes, how should I do this? Otherwise, should I do this in another module?
91982
I'm working with a custom theme (which I did not develop.) We're wanting to add a block to a specific node type, which has a template called node-session.tpl.php. This template prints out all kinds of internal html and php, but is framed by the page.tpl.php file. The node-session.tpl.php contains the code that's printed by the $content variable in page.tpl.php.  I have a new block (created by the AddThis module) that needs to be positioned on the page such that it's nested inside a div created in the node-session.tpl.php. Unfortunately placing the region inside that file doesn't work, and in fact just testing for the variable $add_this itself returns false. According to all the documentation I can find, region variables are available to page template files only. Is there a way I can make the variable available to the node-session.tpl.php file so that I can position the block correctly?
75624
I have a question about getting a path to an image in a Twig template. The image is not assigned to a field or something. Just a static image which is stored in "MYTHEME/image/icon/my-icon.png".  In Drupal 7 I get the path in my node.template with the following code:  &lt;img src="&lt;?php print base_path() . path_to_theme(); ?&gt;/image/icons"&gt;/my-icon.png   How does it work with in Drupal 8? I tried to pass a variable in template_preprocess_node().  MYTHEME.theme:  $variables['images_path'] = \Drupal::theme()-&gt;getActiveTheme()-&gt;getPath() . '/image/';   Twig template:  &lt;img src="{{ images_path  ~ 'icons/' ~ 'my-icon.png' }}"&gt;   It doesn't work. There is no PHP error, but the path is wrongly said to be .
112144
Use case:  I have a custom block:  /**  * Provides a 'Hello' Block  *  * @Block(  *   id = "my",  *   admin_label = @Translation("My Block"),  * )  */ class MyBlock extends BlockBase {    /**    * {@inheritdoc}    */   public function build() {      $build = array(       '#markup' =&gt; 'SOME WEIRD ADS HTML HERE'     );      SOME_COOL_STUFF_TO_ADD_INLINE_JAVASCRIPT_TO_THE_CLOSING_BODY_TAG      return $build;   } }   Is there a way to add inline javascript to the end of the page just when this block is rendered anywhere (in theme or panel page)?
121595
I work in D8, I create a custom module first_module. By modules create a url and display all nodes by *.html.twig file.  Write code in controller.php  public function contentthree() {    $connection = Database::getConnection();    $query = $connection-&gt;select('node', 'n');   $query-&gt;fields('n', ['nid', 'type']);    $groups = $query-&gt;execute()-&gt;fetchAll();    foreach ($groups as $group) {     $events[] = [$group-&gt;nid, $group-&gt;type];   }    return [     '#theme'  =&gt; 'first_module_display',     '#events' =&gt; $events,   ]; }   In *.module  function first_module_theme($existing, $type, $theme, $path) {    return [     'first_module_display' =&gt; [       'variables' =&gt; ['events' =&gt; NULL],       'template'  =&gt; 'first-module-list',     ],   ]; }  function _get_node_details() {    $output = 'Welcome D8';    $output .= 'Node Details';    return $output; }   and create templates first-module-list.html.twig and display data  {%for key, data in events %}  {%for key1, data1 in data %}     {{ data1 }}  {% endfor %}  {% endfor %}   work fine and showing data correct. But, my question is how to call function _get_node_details() and how to render node details in first-module-list.html.twig files?
29490
While nodes, comments, blocks and many other things in Drupal are themed using theme template files (like node.tpl.php), forms are a different story. There are no theme template files for forms. How can I get a particular form to use a custom theme template?
109091
I want to add a new area which will be site wide. Describe the process of getting this new region into my theme, if possible generalize it for adding any new, custom region.
82828
I've searched and found variations of this question but I've never found an answer that seemed to work. I need to add a class to the &lt;li&gt; elements, currently the main menu is rendered like this:  print theme('links__system_main_menu', array(     'links' =&gt; $main_menu,     'attributes' =&gt; array(         'id' =&gt; 'slidemenu',         'class' =&gt; array(             'links',             'inline',             'clearfix'         )     ),     'heading' =&gt; t('') ));   As far as I can tell, this only sets up the &lt;ul&gt; element of the main menu, so I was wondering if there's a way to edit the attributes of the 'links' part.  ---EDIT---  Alright, I think I solved it. Apparently you can use theme_links__system_main_menu in templates to override the whole thing. I ended up doing this:  function mytheme_links__system_main_menu($variables) {     $html = '&lt;div id="mainmenu"&gt;';     $html .= '  &lt;ul id="slidemenu" class="clearfix"&gt;';      static $linkClass = 1;      foreach ($variables['links'] as $link) {                         $html .= '&lt;li class="themastyle' . $linkClass . '"&gt;' . l($link['title'], $link['href'], $link) . '&lt;/li&gt;';         ++$linkClass;     }      $html .= '  &lt;/ul&gt;';     $html .= '&lt;/div&gt;';      return $html; }   Not entirely sure if this is correct Drupal, though it did solve my issue!
25000
I've already added my scripts, but I wanted to know the preferred way. I just put a &lt;script&gt; tag directly in the header.php of my template.  Is there a preferred method of inserting external or custom js files? How would I bind a js file to a single page? (I have the home page in mind)
14734
I'm writing my first WordPress theme and have a question about the use of The Loop in page templates. The page templates I've looked at all follow basically the same pattern (example from Twenty Twelve):  &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;?php get_template_part( 'content', 'page' ); ?&gt; &lt;?php comments_template( '', true ); ?&gt; &lt;?php endwhile; // end of the loop. ?&gt;   But a page will only have one post associated with it so iterating through the posts seems unnecessary. My page template is more readable and seems to work fine:  &lt;?php the_post(); the_title('&lt;h1&gt;', '&lt;/h1&gt;'); the_content(); ?&gt;   Is this a good practice? Are there any downsides?
118094
I am working on Drupal 8, trying to get a page template for each vocabulary. I have tried using hook_theme_suggestions_HOOK_alter() to achieve this, but I was not able to do it.   I tried using Devel with kint(), but no debugging information is shown on my screen.   How can I add a template suggestion for a vocabulary?
36006
I want to know whether form is add/edit in hook_form_alter. In Drupal 7 we can get all these in hook_form_alter.  I tried like this in D7:  function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {   // Check pages(s) , don't use $_GET.     if (strpos($form['#action'], '/add/') !== FALSE) {       $page = 'add';     }     if (strpos($form['#action'], '/edit') !== FALSE) {       $page = 'edit';     } }   Here I am getting add/edit in D7. Whereas in D8 I am not getting any it in $form['#actions']. And i don't want to use $_GET. Is there any way to check add/edit page in hook_form_alter.
31060
says:     Finally, assuming that I'll want to use my style adjustments in a multitude of documents: Where do I put the relevant macro stuff?   The recommended answer is a copy of biblatex.cfg in one's local texmf tree. However, going away from above precondition:  What are all the places, i.e. file types and respective locations, where I can put biblatex style modifications?  I know you can write your own bbx and cbx styles, and there's probably a way to put modifications directly in a tex file? What are the limitations, advantages and disadvantages of each of these, which kind of modification typically goes where, which overrule others ...?
39232
Through API functions, I want to define a new , select it in the current theme, and then insert a few Pages as menu items. This is to be done for instance on a theme activation.  Through a (moderately painful) process of reverse engineering the database inserts and updates after manually setting up the Navigation menu and items, I've pieced together the following steps, where 'footer-nav' is the slug ID of the Navigation menu I'm creating:  if (!term_exists('footer-nav', 'nav_menu')) {      $menu = wp_insert_term('Footer nav', 'nav_menu', array('slug' =&gt; 'footer-nav'));      // Select this menu in the current theme     update_option('theme_mods_'.get_current_theme(), array("nav_menu_locations" =&gt; array("primary" =&gt; $menu['term_id'])));      // Insert new page     $page = wp_insert_post(array('post_title' =&gt; 'Blog',                                  'post_content' =&gt; '',                                  'post_status' =&gt; 'publish',                                  'post_type' =&gt; 'page'));      // Insert new nav_menu_item     $nav_item = wp_insert_post(array('post_title' =&gt; 'News',                                      'post_content' =&gt; '',                                      'post_status' =&gt; 'publish',                                      'post_type' =&gt; 'nav_menu_item'));       add_post_meta($nav_item, '_menu_item_type', 'post_type');     add_post_meta($nav_item, '_menu_item_menu_item_parent', '0');     add_post_meta($nav_item, '_menu_item_object_id', $page);     add_post_meta($nav_item, '_menu_item_object', 'page');     add_post_meta($nav_item, '_menu_item_target', '');     add_post_meta($nav_item, '_menu_item_classes', 'a:1:{i:0;s:0:"";}');     add_post_meta($nav_item, '_menu_item_xfn', '');     add_post_meta($nav_item, '_menu_item_url', '');      wp_set_object_terms($nav_item, 'footer-nav', 'nav_menu'); }   This seems to work, but:   is it a robust and elegant way of doing it? am I missing something totally obvious that would do all this in one line of code?