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
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
add a comment |
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
add a comment |
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
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
templates module drupal-8
asked yesterday
DeveloperDeveloper
65
65
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.Rename "page--my_module.html.twig" to "page--my-module.html.twig". Twig template names should not have underscores.
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 thatpage__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
.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.
- 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
- I am not sure about your structure but it should be like this:
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.Rename "page--my_module.html.twig" to "page--my-module.html.twig". Twig template names should not have underscores.
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 thatpage__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
.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.
- 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
- I am not sure about your structure but it should be like this:
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.
add a comment |
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.Rename "page--my_module.html.twig" to "page--my-module.html.twig". Twig template names should not have underscores.
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 thatpage__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
.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.
- 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
- I am not sure about your structure but it should be like this:
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.
add a comment |
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.Rename "page--my_module.html.twig" to "page--my-module.html.twig". Twig template names should not have underscores.
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 thatpage__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
.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.
- 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
- I am not sure about your structure but it should be like this:
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.
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.Rename "page--my_module.html.twig" to "page--my-module.html.twig". Twig template names should not have underscores.
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 thatpage__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
.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.
- 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
- I am not sure about your structure but it should be like this:
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.
edited 1 hour ago
answered 2 hours ago
zanvidmarzanvidmar
866
866
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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