3

The error I am getting in the development server:

[info] *** Request 2 (0.000/s) [681] [Thu Dec 12 21:05:39 2013] ***
[debug] Path is "homescreen"
[debug] "GET" request for "homescreen" from "192.168.1.100"
[debug] Rendering template "homescreen/homescreen.tt2"
[error] Couldn't render template "homescreen/homescreen.tt2: file error - homescreen/homescreen.tt2: not found"
[error] Couldn't render template "homescreen/homescreen.tt2: file error - homescreen/homescreen.tt2: not found"
[debug] Response Code: 500; Content-Type: text/html; charset=utf-8; Content-Length: 14312
[info] Request took 0.033915s (29.485/s)
.------------------------------------------------------------+-----------.
| Action                                                     | Time      |
+------------------------------------------------------------+-----------+
| /homescreen                                                | 0.000341s |
| /end                                                       | 0.014055s |
|  -> Myproject::View::HTML->process                         | 0.013049s |
'------------------------------------------------------------+-----------'

What I am doing:

I have the following Controller/Homescreen.pm:

package Myproject::Controller::Homescreen;

use strict;
use warnings;
use parent 'Catalyst::Controller';
use Data::Dumper;
use JSON;

__PACKAGE__->config->{namespace} = '';

sub homescreen :Path('/homescreen') :Args(0)  {

        my ( $self, $c ) = @_;
        print STDERR "IN THE HOMESCREEN ACTION\n";


        $c->stash({template => 'homescreen/homescreen.tt2',
                   title => 'Home Screen'
                 });
}

I have the following View/HTML.pm:

package Myproject::View::HTML;
use Moose;
use namespace::autoclean;

extends 'Catalyst::View::TT';

__PACKAGE__->config({
    #Changed default TT extension to TT2
    TEMPLATE_EXTENSION => '.tt2',
    render_die => 1,
});

I have the following lib/Myproject.pm:

__PACKAGE__->config(
    name => 'Myproject',
    # Disable deprecated behavior needed by old applications
    disable_component_resolution_regex_fallback => 1,
    #enable_catalyst_header => 1, # Send X-Catalyst header
);

__PACKAGE__->config(
        #Configure the view
        'View::HMTL' => {
                #Set the location for TT files
                INCLUDE_PATH => [
                        __PACKAGE__->path_to( 'root', 'src' ),
                ],
        },
);


# Start the application
__PACKAGE__->setup();

I then have a root/src/homescreen/homescreen.tt2 withing my Catalyst directory that contains all my html code (eventually it will use the template toolkit,but at the moment it is purely html and javscript code which I know is fine).

The error I get on the application page in my browser is:

Couldn't render template "homescreen/homescreen.tt2: file error - homescreen/homescreen.tt2: not found" 

I have tried using DEBUG => 'undef' in my HTML.pm View to help with debugging, but I don't seem to get any extra output.

There is probably something very obvious I am overlooking but I cannot work out what it is.

Update

I have just noticed the following in the Config section of my browser debug screen:

Config

  do {
  my $a = {
    "Action::RenderView" => {
      ignore_classes => [
                          "DBIx::Class::ResultSource::Table",
                          "DBIx::Class::ResultSourceHandle",
                          "DateTime",
                        ],
      scrubber_func  => sub { ... },
    },
    "disable_component_resolution_regex_fallback" => 1,
    "home" => "/home/fred/Myproject",
    "name" => "Myproject",
    "Plugin::ConfigLoader" => {},
    "Plugin::Static::Simple" => {
      debug => 1,
      dirs => [],
      ignore_dirs => [],
      ignore_extensions => ["tmpl", "tt", "tt2", "html", "xhtml"],   <---- IS THIS SIGNIFICANT AT ALL?
      include_path => [
        bless({
          dirs => ["", "home", "fred", "Myproject", "root"],
          file_spec_class => undef,
          volume => "",
        }, "Path::Class::Dir"),
      ],
      mime_types => {},
      mime_types_obj => bless({}, "MIME::Types"),
      no_logs => 1,
    },
    "root" => 'fix',
    "stacktrace" => { context => 3, verbose => 0 },
    "static" => 'fix',
    "View::HMTL" => {
      INCLUDE_PATH => [
        bless({
          dirs => ["", "home", "fred", "Myproject", "root", "src"],
          file_spec_class => undef,
          volume => "",
        }, "Path::Class::Dir"),
      ],
    },
  };
  $a->{"root"} = $a->{"Plugin::Static::Simple"}{include_path}[0];
  $a->{"static"} = $a->{"Plugin::Static::Simple"};
  $a;
}

I take it this means it is ignoring my template file because it has the .tt2 file extension?

However, I am not setting this ignore_extensions attribute anywhere in my Catalyst project? Is this the cause of my problem or something totally unrelated?

halfer
  • 19,824
  • 17
  • 99
  • 186
yonetpkbji
  • 1,019
  • 2
  • 21
  • 35
  • Are you the root user? Maybe your webserver is not running as root and thus cannot find the template. Try loading [CWD](http://perldoc.perl.org/Cwd.html) and let put something like `die cwd;` in your controller to see where your stuff is running. If it's in another user's homedir, chances are that user has no permission to read files in `/root`. – simbabque Dec 12 '13 at 21:43
  • I did check file permissions before posting (which I forgot to mention). Also, I did just try running the development server as root, but it made no difference. I still get the same error message. Any other ideas? thanks – yonetpkbji Dec 12 '13 at 21:48
  • Dump out `__PACKAGE__->config->{'View::HTML'}` to STDERR and confirm the path is what you anticipate it should be. – RET Dec 13 '13 at 00:47
  • Have you try to give the full path to your template in the controller? – Fotis_zzz Dec 13 '13 at 09:28
  • Also try to remove "root" from __PACKAGE__->path_to in the lib/Myproject.pm file – Fotis_zzz Dec 13 '13 at 10:10
  • 2
    The template has to be in the directory 'root/src/homescreen' within the catalyst project directory, not in '/root/src/homescreen'. – dgw Dec 13 '13 at 21:04
  • @dgw - Apologies, my template is in the 'root/src/homescreen' within the catalyst project directory... it was a typo on my part that has now been edited, thanks – yonetpkbji Dec 20 '13 at 22:15
  • @RET - When using `print STDERR __PACKAGE__->config->{'View::HTML'};` as you suggested I get an error in the Catalyst debug output `Use of uninitialized value in print at /home/fred/MyProject/script/../lib/MyProject/Controller/Homescreen.pm line 10.` – yonetpkbji Dec 20 '13 at 22:21
  • Well, I did mean `print STDERR Dumper(__PACKAGE__->..)`, but possibly it's too early in the chain for that to work correctly. Is the problem resolved? – RET Dec 21 '13 at 02:03
  • No, it's still not fixed, still getting the `Couldn't render template...` issue. I'm sure it must be something obvious but cannot see what... – yonetpkbji Dec 21 '13 at 15:08
  • Pretty certain it's not a permissions issue because I changed whole directory to 777 with `chmod -R ` to make sure, but still nothing changed. – yonetpkbji Dec 21 '13 at 15:52
  • Just found something that may or may not be of significance, please see the update to my question... thanks a lot – yonetpkbji Dec 21 '13 at 16:12
  • The ignore_extensions is only for the Static::Simple plugin, so that isn't the problem. See the answer below for the solution :-) – asjo Dec 21 '13 at 22:02

1 Answers1

1

It looks like your configuration isn't taking effect. Try putting your template in root/homescreen/homescreen.tt2 instead of root/src/homescreen/homescreen.tt2, and Catalyst finds it.

Ahh, you have a typo in your lib/Myproject.pm:

__PACKAGE__->config(
        #Configure the view
        'View::HMTL' => {

Try 'View::HTML' instead (notice you have HMTL - wrong spelling).

asjo
  • 3,084
  • 2
  • 26
  • 20
  • Great spot, thanks... I was expecting it to be something obvious but not quite that obvious... the amount of times I've looked at this I should of spotted it -thanks again – yonetpkbji Dec 22 '13 at 12:48
  • 1
    RET's First Theorem: the problem with debugging is the solution is the last thing you would think of. :-) – RET Dec 22 '13 at 22:54