Drupal 8 assign module template to a page2019 Community Moderator ElectionUse 'class' or 'typename' for template parameters?How do I unload (reload) a Python module?Why can templates only be implemented in the header file?Where and why do I have to put the “template” and “typename” keywords?How can I get a list of locally installed Python modules?Drupal 7 theme template file names not workinghow do i migrate custom module from drupal 7.39 to drupal 8.0.5Template for custom page Drupal 8How do I alter a node template from a module in Drupal 8?Use httpClient - Guzzle for Drupal 8 custom module

Professor forcing me to attend a conference

The Key to the Door

A bug in Excel? Conditional formatting for marking duplicates also highlights unique value

I can't die. Who am I?

“I had a flat in the centre of town, but I didn’t like living there, so …”

Why aren't there more gauls like Obelix?

What is the meaning of option 'by' in TikZ Intersections

Ultrafilters as a double dual

Naming Characters after Friends/Family

How can I be pwned if I'm not registered on the compromised site?

Is divide-by-zero a security vulnerability?

Problems with rounding giving too many digits

Why do we call complex numbers “numbers” but we don’t consider 2 vectors numbers?

If nine coins are tossed, what is the probability that the number of heads is even?

Can a space-faring robot still function over a billion years?

Short story about an infectious indestructible metal bar?

Are small insurances worth it

What can I do if someone tampers with my SSH public key?

Error in TransformedField

Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?

Can you run a ground wire from stove directly to ground pole in the ground

Under what conditions would I NOT add my Proficiency Bonus to a Spell Attack Roll (or Saving Throw DC)?

Do natural melee weapons (from racial traits) trigger Improved Divine Smite?

School performs periodic password audits. Is my password compromised?



Drupal 8 assign module template to a page



2019 Community Moderator ElectionUse 'class' or 'typename' for template parameters?How do I unload (reload) a Python module?Why can templates only be implemented in the header file?Where and why do I have to put the “template” and “typename” keywords?How can I get a list of locally installed Python modules?Drupal 7 theme template file names not workinghow do i migrate custom module from drupal 7.39 to drupal 8.0.5Template for custom page Drupal 8How do I alter a node template from a module in Drupal 8?Use httpClient - Guzzle for Drupal 8 custom module










0















I am new in drupal and i am creating a module to allow customers to customize card using fabric js. I created a module and inside it i have created a template file inside my_module > templates > page--my_module.html.twig. The issue is that i am not able to view the content of the template on a page.



Here is the code of my my_module.module file



 <?php

use DrupalCoreRoutingRouteMatchInterface;

/**
* Implements hook_help().
*/
function my_module_help($route_name, RouteMatchInterface $route_match)
switch ($route_name)
case 'help.page.my_module':
return t('
<h2>Lorem ipsum generator for Drupal.</h2>
<h3>Instructions</h3>
<p>Lorem ipsum dolor sit amet... <strong>Just kidding!</strong></p>
<p>Unpack in the <em>modules</em> folder (currently in the root of your Drupal 8 installation) and enable in <strong>/admin/modules</strong>.</p>
<p>Then, visit <strong>/admin/config/development/loremipsum</strong> and enter your own set of phrases to build random-generated text (or go with the default Lorem ipsum).</p>
<p>Last, visit <strong>www.example.com/loremipsum/generate/P/S</strong> where:</p>
<ul>
<li><em>P</em> is the number of <em>paragraphs</em></li>
<li><em>S</em> is the maximum number of <em>sentences</em></li>
</ul>
<p>There is also a generator block in which you can choose how many paragraphs and
phrases and it'll do the rest.</p>
<p>If you need, there's also a specific <em>generate lorem ipsum</em> permission.</p>
<h3>Attention</h3>
<p>Most bugs have been ironed out, holes covered, features added. But this module is a work in progress. Please report bugs and suggestions, ok?</p>
');



/**
* Implements hook_theme() to add the template definition.
**/
function my_module_theme($existing, $type, $theme, $path)
return array(
'my_module_template' => array(
'template' => 'page--my_module',
'variables' => array('test_var' => NULL),
),
);



Here is the code of the controller MyModuleController.php



 <?php
/**
* @file
* Contains Drupalcard_designerControllerFirstController.
*/

namespace Drupalmy_moduleController;

use DrupalCoreControllerControllerBase;

class MyModuleController extends ControllerBase
public function content()
return array(
'#theme' => 'card_designer_template',
'#test_var' => $this->t('Test Value'),
);




Here is the code of my_module.routing.yml



 my_module.content:
path: '/card-design'
defaults:
_controller: 'Drupalmy_moduleControllerMyModuleController::content'
_title: 'Hello world'
requirements:
_permission: 'access content'**strong text**


And here is the page--my_module.html.twig file



<p> This is the lotus template with a value of test_var </p>


Now don't know how to assign this my custom template to a page so that i can check the output of the template on a the website.



Can anyone tell me where i am wrong and how i can see the output on a page.



Thanks in advance.










share|improve this question


























    0















    I am new in drupal and i am creating a module to allow customers to customize card using fabric js. I created a module and inside it i have created a template file inside my_module > templates > page--my_module.html.twig. The issue is that i am not able to view the content of the template on a page.



    Here is the code of my my_module.module file



     <?php

    use DrupalCoreRoutingRouteMatchInterface;

    /**
    * Implements hook_help().
    */
    function my_module_help($route_name, RouteMatchInterface $route_match)
    switch ($route_name)
    case 'help.page.my_module':
    return t('
    <h2>Lorem ipsum generator for Drupal.</h2>
    <h3>Instructions</h3>
    <p>Lorem ipsum dolor sit amet... <strong>Just kidding!</strong></p>
    <p>Unpack in the <em>modules</em> folder (currently in the root of your Drupal 8 installation) and enable in <strong>/admin/modules</strong>.</p>
    <p>Then, visit <strong>/admin/config/development/loremipsum</strong> and enter your own set of phrases to build random-generated text (or go with the default Lorem ipsum).</p>
    <p>Last, visit <strong>www.example.com/loremipsum/generate/P/S</strong> where:</p>
    <ul>
    <li><em>P</em> is the number of <em>paragraphs</em></li>
    <li><em>S</em> is the maximum number of <em>sentences</em></li>
    </ul>
    <p>There is also a generator block in which you can choose how many paragraphs and
    phrases and it'll do the rest.</p>
    <p>If you need, there's also a specific <em>generate lorem ipsum</em> permission.</p>
    <h3>Attention</h3>
    <p>Most bugs have been ironed out, holes covered, features added. But this module is a work in progress. Please report bugs and suggestions, ok?</p>
    ');



    /**
    * Implements hook_theme() to add the template definition.
    **/
    function my_module_theme($existing, $type, $theme, $path)
    return array(
    'my_module_template' => array(
    'template' => 'page--my_module',
    'variables' => array('test_var' => NULL),
    ),
    );



    Here is the code of the controller MyModuleController.php



     <?php
    /**
    * @file
    * Contains Drupalcard_designerControllerFirstController.
    */

    namespace Drupalmy_moduleController;

    use DrupalCoreControllerControllerBase;

    class MyModuleController extends ControllerBase
    public function content()
    return array(
    '#theme' => 'card_designer_template',
    '#test_var' => $this->t('Test Value'),
    );




    Here is the code of my_module.routing.yml



     my_module.content:
    path: '/card-design'
    defaults:
    _controller: 'Drupalmy_moduleControllerMyModuleController::content'
    _title: 'Hello world'
    requirements:
    _permission: 'access content'**strong text**


    And here is the page--my_module.html.twig file



    <p> This is the lotus template with a value of test_var </p>


    Now don't know how to assign this my custom template to a page so that i can check the output of the template on a the website.



    Can anyone tell me where i am wrong and how i can see the output on a page.



    Thanks in advance.










    share|improve this question
























      0












      0








      0








      I am new in drupal and i am creating a module to allow customers to customize card using fabric js. I created a module and inside it i have created a template file inside my_module > templates > page--my_module.html.twig. The issue is that i am not able to view the content of the template on a page.



      Here is the code of my my_module.module file



       <?php

      use DrupalCoreRoutingRouteMatchInterface;

      /**
      * Implements hook_help().
      */
      function my_module_help($route_name, RouteMatchInterface $route_match)
      switch ($route_name)
      case 'help.page.my_module':
      return t('
      <h2>Lorem ipsum generator for Drupal.</h2>
      <h3>Instructions</h3>
      <p>Lorem ipsum dolor sit amet... <strong>Just kidding!</strong></p>
      <p>Unpack in the <em>modules</em> folder (currently in the root of your Drupal 8 installation) and enable in <strong>/admin/modules</strong>.</p>
      <p>Then, visit <strong>/admin/config/development/loremipsum</strong> and enter your own set of phrases to build random-generated text (or go with the default Lorem ipsum).</p>
      <p>Last, visit <strong>www.example.com/loremipsum/generate/P/S</strong> where:</p>
      <ul>
      <li><em>P</em> is the number of <em>paragraphs</em></li>
      <li><em>S</em> is the maximum number of <em>sentences</em></li>
      </ul>
      <p>There is also a generator block in which you can choose how many paragraphs and
      phrases and it'll do the rest.</p>
      <p>If you need, there's also a specific <em>generate lorem ipsum</em> permission.</p>
      <h3>Attention</h3>
      <p>Most bugs have been ironed out, holes covered, features added. But this module is a work in progress. Please report bugs and suggestions, ok?</p>
      ');



      /**
      * Implements hook_theme() to add the template definition.
      **/
      function my_module_theme($existing, $type, $theme, $path)
      return array(
      'my_module_template' => array(
      'template' => 'page--my_module',
      'variables' => array('test_var' => NULL),
      ),
      );



      Here is the code of the controller MyModuleController.php



       <?php
      /**
      * @file
      * Contains Drupalcard_designerControllerFirstController.
      */

      namespace Drupalmy_moduleController;

      use DrupalCoreControllerControllerBase;

      class MyModuleController extends ControllerBase
      public function content()
      return array(
      '#theme' => 'card_designer_template',
      '#test_var' => $this->t('Test Value'),
      );




      Here is the code of my_module.routing.yml



       my_module.content:
      path: '/card-design'
      defaults:
      _controller: 'Drupalmy_moduleControllerMyModuleController::content'
      _title: 'Hello world'
      requirements:
      _permission: 'access content'**strong text**


      And here is the page--my_module.html.twig file



      <p> This is the lotus template with a value of test_var </p>


      Now don't know how to assign this my custom template to a page so that i can check the output of the template on a the website.



      Can anyone tell me where i am wrong and how i can see the output on a page.



      Thanks in advance.










      share|improve this question














      I am new in drupal and i am creating a module to allow customers to customize card using fabric js. I created a module and inside it i have created a template file inside my_module > templates > page--my_module.html.twig. The issue is that i am not able to view the content of the template on a page.



      Here is the code of my my_module.module file



       <?php

      use DrupalCoreRoutingRouteMatchInterface;

      /**
      * Implements hook_help().
      */
      function my_module_help($route_name, RouteMatchInterface $route_match)
      switch ($route_name)
      case 'help.page.my_module':
      return t('
      <h2>Lorem ipsum generator for Drupal.</h2>
      <h3>Instructions</h3>
      <p>Lorem ipsum dolor sit amet... <strong>Just kidding!</strong></p>
      <p>Unpack in the <em>modules</em> folder (currently in the root of your Drupal 8 installation) and enable in <strong>/admin/modules</strong>.</p>
      <p>Then, visit <strong>/admin/config/development/loremipsum</strong> and enter your own set of phrases to build random-generated text (or go with the default Lorem ipsum).</p>
      <p>Last, visit <strong>www.example.com/loremipsum/generate/P/S</strong> where:</p>
      <ul>
      <li><em>P</em> is the number of <em>paragraphs</em></li>
      <li><em>S</em> is the maximum number of <em>sentences</em></li>
      </ul>
      <p>There is also a generator block in which you can choose how many paragraphs and
      phrases and it'll do the rest.</p>
      <p>If you need, there's also a specific <em>generate lorem ipsum</em> permission.</p>
      <h3>Attention</h3>
      <p>Most bugs have been ironed out, holes covered, features added. But this module is a work in progress. Please report bugs and suggestions, ok?</p>
      ');



      /**
      * Implements hook_theme() to add the template definition.
      **/
      function my_module_theme($existing, $type, $theme, $path)
      return array(
      'my_module_template' => array(
      'template' => 'page--my_module',
      'variables' => array('test_var' => NULL),
      ),
      );



      Here is the code of the controller MyModuleController.php



       <?php
      /**
      * @file
      * Contains Drupalcard_designerControllerFirstController.
      */

      namespace Drupalmy_moduleController;

      use DrupalCoreControllerControllerBase;

      class MyModuleController extends ControllerBase
      public function content()
      return array(
      '#theme' => 'card_designer_template',
      '#test_var' => $this->t('Test Value'),
      );




      Here is the code of my_module.routing.yml



       my_module.content:
      path: '/card-design'
      defaults:
      _controller: 'Drupalmy_moduleControllerMyModuleController::content'
      _title: 'Hello world'
      requirements:
      _permission: 'access content'**strong text**


      And here is the page--my_module.html.twig file



      <p> This is the lotus template with a value of test_var </p>


      Now don't know how to assign this my custom template to a page so that i can check the output of the template on a the website.



      Can anyone tell me where i am wrong and how i can see the output on a page.



      Thanks in advance.







      templates module drupal-8






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      DeveloperDeveloper

      65




      65






















          1 Answer
          1






          active

          oldest

          votes


















          0














          1. In "my_module.routing.yml" fix _permission: 'access content'**strong text**to _permission: 'access content'. I am not sure where did you get **strong text** but it should not be here.


          2. Rename "page--my_module.html.twig" to "page--my-module.html.twig". Twig template names should not have underscores.


          3. In "MyModuleController.php" change '#theme' => 'card_designer_template', to '#theme' => 'page__my_module', because machine name of template must match all others theme naming usages. Please note that page__my_module is using underscores when used in PHP, but when used as name of twig template file, underscores are converted to hyphens => page--my-module.html.twig.


          4. In "my_module.module" Change


          'my_module_template' => array(
          'template' => 'page--my_module',
          'variables' => array('test_var' => NULL),
          ),


          to



          'page__my_module' => array(
          'variables' => array('test_var' => NULL),
          ),



          because template machine name must be parent key and variables should be child key. Also "template" key can be removed, because after fix it is defined in parent key as already said.



          1. I am not sure if you have "my_module.info.yml" but is should be something like:

          name: my_module
          type: module
          description: 'My custom module'
          package: 'Custom'
          core: 8.x


          1. I am not sure about your structure but it should be like this:

          enter image description here



          I hope I did not missed anything :) I fixed and tested your code, so if it does not work, let me know and I will fix my answer.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55023140%2fdrupal-8-assign-module-template-to-a-page%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            1. In "my_module.routing.yml" fix _permission: 'access content'**strong text**to _permission: 'access content'. I am not sure where did you get **strong text** but it should not be here.


            2. Rename "page--my_module.html.twig" to "page--my-module.html.twig". Twig template names should not have underscores.


            3. In "MyModuleController.php" change '#theme' => 'card_designer_template', to '#theme' => 'page__my_module', because machine name of template must match all others theme naming usages. Please note that page__my_module is using underscores when used in PHP, but when used as name of twig template file, underscores are converted to hyphens => page--my-module.html.twig.


            4. In "my_module.module" Change


            'my_module_template' => array(
            'template' => 'page--my_module',
            'variables' => array('test_var' => NULL),
            ),


            to



            'page__my_module' => array(
            'variables' => array('test_var' => NULL),
            ),



            because template machine name must be parent key and variables should be child key. Also "template" key can be removed, because after fix it is defined in parent key as already said.



            1. I am not sure if you have "my_module.info.yml" but is should be something like:

            name: my_module
            type: module
            description: 'My custom module'
            package: 'Custom'
            core: 8.x


            1. I am not sure about your structure but it should be like this:

            enter image description here



            I hope I did not missed anything :) I fixed and tested your code, so if it does not work, let me know and I will fix my answer.






            share|improve this answer





























              0














              1. In "my_module.routing.yml" fix _permission: 'access content'**strong text**to _permission: 'access content'. I am not sure where did you get **strong text** but it should not be here.


              2. Rename "page--my_module.html.twig" to "page--my-module.html.twig". Twig template names should not have underscores.


              3. In "MyModuleController.php" change '#theme' => 'card_designer_template', to '#theme' => 'page__my_module', because machine name of template must match all others theme naming usages. Please note that page__my_module is using underscores when used in PHP, but when used as name of twig template file, underscores are converted to hyphens => page--my-module.html.twig.


              4. In "my_module.module" Change


              'my_module_template' => array(
              'template' => 'page--my_module',
              'variables' => array('test_var' => NULL),
              ),


              to



              'page__my_module' => array(
              'variables' => array('test_var' => NULL),
              ),



              because template machine name must be parent key and variables should be child key. Also "template" key can be removed, because after fix it is defined in parent key as already said.



              1. I am not sure if you have "my_module.info.yml" but is should be something like:

              name: my_module
              type: module
              description: 'My custom module'
              package: 'Custom'
              core: 8.x


              1. I am not sure about your structure but it should be like this:

              enter image description here



              I hope I did not missed anything :) I fixed and tested your code, so if it does not work, let me know and I will fix my answer.






              share|improve this answer



























                0












                0








                0







                1. In "my_module.routing.yml" fix _permission: 'access content'**strong text**to _permission: 'access content'. I am not sure where did you get **strong text** but it should not be here.


                2. Rename "page--my_module.html.twig" to "page--my-module.html.twig". Twig template names should not have underscores.


                3. In "MyModuleController.php" change '#theme' => 'card_designer_template', to '#theme' => 'page__my_module', because machine name of template must match all others theme naming usages. Please note that page__my_module is using underscores when used in PHP, but when used as name of twig template file, underscores are converted to hyphens => page--my-module.html.twig.


                4. In "my_module.module" Change


                'my_module_template' => array(
                'template' => 'page--my_module',
                'variables' => array('test_var' => NULL),
                ),


                to



                'page__my_module' => array(
                'variables' => array('test_var' => NULL),
                ),



                because template machine name must be parent key and variables should be child key. Also "template" key can be removed, because after fix it is defined in parent key as already said.



                1. I am not sure if you have "my_module.info.yml" but is should be something like:

                name: my_module
                type: module
                description: 'My custom module'
                package: 'Custom'
                core: 8.x


                1. I am not sure about your structure but it should be like this:

                enter image description here



                I hope I did not missed anything :) I fixed and tested your code, so if it does not work, let me know and I will fix my answer.






                share|improve this answer















                1. In "my_module.routing.yml" fix _permission: 'access content'**strong text**to _permission: 'access content'. I am not sure where did you get **strong text** but it should not be here.


                2. Rename "page--my_module.html.twig" to "page--my-module.html.twig". Twig template names should not have underscores.


                3. In "MyModuleController.php" change '#theme' => 'card_designer_template', to '#theme' => 'page__my_module', because machine name of template must match all others theme naming usages. Please note that page__my_module is using underscores when used in PHP, but when used as name of twig template file, underscores are converted to hyphens => page--my-module.html.twig.


                4. In "my_module.module" Change


                'my_module_template' => array(
                'template' => 'page--my_module',
                'variables' => array('test_var' => NULL),
                ),


                to



                'page__my_module' => array(
                'variables' => array('test_var' => NULL),
                ),



                because template machine name must be parent key and variables should be child key. Also "template" key can be removed, because after fix it is defined in parent key as already said.



                1. I am not sure if you have "my_module.info.yml" but is should be something like:

                name: my_module
                type: module
                description: 'My custom module'
                package: 'Custom'
                core: 8.x


                1. I am not sure about your structure but it should be like this:

                enter image description here



                I hope I did not missed anything :) I fixed and tested your code, so if it does not work, let me know and I will fix my answer.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 1 hour ago

























                answered 2 hours ago









                zanvidmarzanvidmar

                866




                866





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55023140%2fdrupal-8-assign-module-template-to-a-page%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme