I'm a beginner in symfony 4, I create a symfony 4 project But I get this error after adding boostrap themes
Unable to find template "blog/home.html.twig" (looked into:
D:\Interactions\Symfony4\demo\vendor\symfony\twig-
bridge/Resources/views/Form).
This is my action code in the controller:
/**
* #Route("/", name="home")
*/
public function home()
{
return $this->render('blog/home.html.twig');
}
Any suggestions to fix that ?
This the content of My twig.yaml:
twig:
default_path: '%kernel.project_dir%/templat:es'
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
form_themes: ['bootstrap_4_layout.html.twig']
Try fixing
default_path: '%kernel.project_dir%/templat:es'
with
default_path: '%kernel.project_dir%/templates'
and finally clear the cache
Related
After looking at a bunch of modules I am still confused as to how I can take a content piece I've created (a Server), make my own custom module (servers) and do some logic so I can pass that on to a servers-template.
servers.info.yml
name: Servers Module
description: Creates a Servers Module
package: Servers
type: module
core: 8.x
servers.module
<?php
function servers_theme(){
$theme['server_page'] = [
'variables' =>['name' => NULL],
'template' => 'server',
];
return $theme;
}
And I am not sure if this is correct, but my servers.routing.yml
servers.server: #Pretty sure this part doesn't matter
path: '/node/{server}' #I'd like to have /server/{server/ but my content's url is /node/xx
defaults:
_title: 'Servers'
_controller: '\Drupal\servers\Controller\Servers::getServersImplementation'
entity_type: 'server' #Not sure if this is correct
requirements:
_permission: 'access content' #Do I need this?
Controller
#located in servers/src/controller/Servers.php
namespace Drupal\Servers\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Controller for js_example pages.
*
* #ingroup js_example
*/
class Servers extends ControllerBase {
/**
* Accordion page implementation.
*
* We're allowing a twig template to define our content in this case,
* which isn't normally how things work, but it's easier to demonstrate
* the JavaScript this way.
*
* #return array
* A renderable array.
*/
public function getServersImplementation($name)
{
return[
'#theme'=>'server_page',
'#name'=>$name,
];
}
}
Absolutely nothing shows up when I've enabled the module. I know it's enabled because I can change the routing path to a node id /node/93 and that node will give me a page not found error, when without the routing I can get the content.
No errors are present in the error.log, or recent log messages. I am quite confused with this in D8, but once I can get this concept I know I will be able to understand all I need to complete my modules.
Thanks in advance.
Can anyone help me with a Symfony 2 (I'm newby with it).
I just installed framework, created my own bundle and it worked fine till I switched template engine from Twig to PHP.
The steps I did:
specified templating: { engines: ['php', 'twig'] } in config.yml
renamed view file from hello.html.twig to hello.html.php
changed twig template code to php's echo
Also if inside the action I leave:
return $this->render('MyBundle:Default:index.html.php', array('name' => $name));
all OK, but when I changes it to:
return array('name' => $name);
Symfony shows me an error: Unable to find template "MyBundle:Default:index.html.twig"
I assume you use the #Template() annotation? From the official documentation:
If you are using PHP as a templating system, you need to make it
explicit::
/**
* #Template(engine="php")
*/
public function showAction($id)
{
// ...
}
So you should add engine="php" to the annotation.
I've generated testsuits via "cake bake testsuit" and used localhost/test.php for my app.
So, the is an error when I tried to run one of test (else tests are valid):
Fatal error: Class 'ErrorHandler' not found in Z:\home\prodvigator\www\cake\libs\object.php on line 201
This models and controllers are generated by scaffold and I don't think that an error is in this sources.
Using:
CakePHP 1.3
The latest SimpleTest
In my case, deleting all the files in the folder /app/tmp/cache/persistent solved the problem.
try checking the generated tests for an error that gets written at the top of the file.
sometimes i've been known to find something like this in both model and controller tests.
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead in /projectname/cake/console/templates/default/classes/test.ctp on line 22
In my case, the error was:
Fatal error: Uncaught Error: Class 'ErrorHandler' not found in C:\[path]\core\cake\libs\object.php on line 211
( ! ) Error: Class 'ErrorHandler' not found in C:\[path]\core\cake\libs\object.php on line 211
The error was happening to me when trying to visit http://localhost/user_accounts/index
I already had the view created at app\views\user_accounts\index.ctp with the following content:
<div>
Text from div
</div>
I had created the corresponding controller as well at app\controllers\user_accounts_controller.php:
<?php
class UserAccountsController extends AppController {
public function index() {
// Render the view in /views/user_accounts/index.ctp
$this->render();
}
}
?>
Since I was not associating a model to this controller, I was missing this: var $uses = array();. It would have saved me time if the error had been more explicit, something such as "You do not have a model associated to this controller".
The fix was:
<?php
class UserAccountsController extends AppController {
// Use this controller without a need for a corresponding Model file.
var $uses = array();
public function index() {
// Render the view in /views/user_accounts/index.ctp
$this->render();
}
}
?>
I am writing a component test in cakephp
here is my code
<?php
class PermissionTestCase extends CakeTestCase {
var $fixtures = array('Org');
function testsetPermission() {
$this->PermissionComponentTest = new PermissionComponent(); <---- line 5
I get this error - Fatal error: Class 'PermissionComponent' not found in /Sites/php/cake/Demo_Code/perm/app/tests/cases/components/permission.test.php on line 5
Why is it looking for the component in tests/cases ?
Also I tried moving the component into this directory and it didnt work.
Thanks
Alex
You have to include the component manually with App::import():
App::import('Component', 'Permission');
From another forum I found the following example:
"I was looking for a way to pull node data via ajax and came up with the following solution for Drupal 6. After implementing the changes below, if you add ajax=1 in the URL (e.g. mysite.com/node/1?ajax=1), you'll get just the content and no page layout.
in the template.php file for your theme:
function phptemplate_preprocess_page(&$vars) {
if ( isset($_GET['ajax']) && $_GET['ajax'] == 1 ) {
$vars['template_file'] = 'page-ajax';
}
}
then create page-ajax.tpl.php in your theme directory with this content:
<?php print $content; ?>
"
This seems like the logical way to do it and I did this, but the phptemplate_preprocess_page function is never called ... any suggestions?
I figured it out for myself from a Drupal Support Theme Development page:
"Maybe this helps
leahcim.2707 - May 29, 2008 - 05:40
I was trying to get the same thing done and for me this works, but I'm not sure if it is the correct way as I'm still new to Drupal:
in "template.php" I added the following function:
function phptemplate_preprocess_page(&$vars)
{
$css = $vars['css'];
unset($css['all']['module']['modules/system/system.css']);
unset($css['all']['module']['modules/system/defaults.css']);
$vars['styles'] = drupal_get_css($css);
}
I think after adding the function you need to go to /admin/build/themes so that Drupal recognises the function."
The part in bold is what did the trick ... you have to re-save the configuration so it recognizes that you've added a new function to the template.