Welcome Guest, Not a member yet? Register   Sign In
Phil Sturgeon's Template Library?
#11

[eluser]hugle[/eluser]
Hello Phil and others Smile

I came with some problems here..

For example I have module, called 'categories'.

In the controller of this, module, I do:
Code:
$this->template->set_theme('admin');
$this->template->build('topnav');

I get the error:
Code:
Unable to locate the file: categories/topnav.php
But this file is located in:
Code:
/application/themes/admin/views/topnav.php

Later I tried to put this file into:
Code:
/application/modules/categories/views/topnav.php

- no such error, all works OK.

How I can make Module use a theme? or maybe it is not possible?

Thank you very much!
#12

[eluser]Phil Sturgeon[/eluser]
Application/themes/views/modules/modulename/whatever.php
#13

[eluser]hugle[/eluser]
[quote author="Phil Sturgeon" date="1271512588"]Application/themes/views/modules/modulename/whatever.php[/quote]

strange, but I can't get it to work...
(admin is theme name)
I did:
Code:
$this->template->set_theme('admin');

I tried:
Application/themes/views/modules/modulename/whatever.php
Application/themes/views/modules/modulename/views/whatever.php

Application/themes/admin/views/modules/modulename/whatever.php
Application/themes/admin/views/modules/modulename/views/whatever.php

Application/themes/admin/modules/categories/whatever.php
Application/themes/admin/modules/categories/views/whatever.php
-- nothing workedSad
my temalate.php config is the default one.


What I am trying to to, is that I need a little app, with and admin backend.
for heavier projects I use Pyro.
But I came to a solution, that it's a time to start using templates, it's cleaner, easier to adapt to new projects/designs.
I looked threw Pyro for examples, and started using Template Library

I have an example controller 'categories' (extending Admin_Controller) - admin.php
and one controller is extending Public_Controller - categories.php

Code:
these both files located in same directory:
/app/modules/categories/controllers/admin.php
/app/modules/categories/controllers/categories.php

now when I want for example build a 'form.php' view which is located at:
/app/modules/categories/controllers/views/form.php

I have also this layout:
/app/themes/admin/views/layout.php

So when I do:
Code:
$this->template->set_theme('admin');
$this->template->set_layout('layout');
$this->template->build('form', $data);

Shouldn't it work?
Maybe I'm missleading you, and miss understanding something...
So I decided to describe whole problem...

Thank you!
#14

[eluser]MrCevic[/eluser]
Hi Devon,
I've been trying different ways of using Phil's library following the comments in this thread and playing with PyroCms with no success. Would you be so kind as to tell us how you made it work for you? I won't mind writing some documentation if I can make it work!

Just in case, here's what I've done:

1 - Dropped Template.php "system/application/libraries"
2 - Created a MY_Controller.php in "system/application/libraries" with the following code:

Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class MY_Controller extends Controller
{
    function __construct()
    {
        parent::Controller();
        $this->load->library('template');
        $this->template->set_theme('default');
        $this->template->set_layout('layout');
    }
}
?>
3 - Created a layout.php and placed it in "system/application/themes/default/views". layout.php has the following code:
Code:
<?=doctype()?>
<html>
    <head>
        <title><?php echo $template['title']; ?></title>
        <?php echo $template['metadata']; ?>                    
    </head>

    <body>
        <div class="container">
        &lt;?php echo $template['body']; ?&gt;
        </div>
        <div id="footer">Copyright 2010</div>
    &lt;/body&gt;
&lt;/html&gt;
4 - And this is my welcome.php controller:
Code:
&lt;?php
class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();
    }
    
    function index()
    {
    $data['saysomething'] = 'saysomething';
    $this->template->build('layout', $data);
    }
}
?&gt;


Here's what I get:
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined property: Welcome::$template
Filename: controllers/welcome.php
Line Number: 19

Fine. Just in case I go and modify my welcome.php controller and add "$this->load->library('template');" just after "parent::Controller();". This is what I get:
Quote:An Error Was Encountered
Unable to locate the file: layout.php
#15

[eluser]Phil Sturgeon[/eluser]
Application/themes/admin/views/modules/modulename/whatever.php should be fine.

"it doesn't work" is not very descriptive about the actual problem you are getting. Error messages? Screenshots?
#16

[eluser]MrCevic[/eluser]
Hi Phil, I've just updated my question with more information on how I'm using your library and the problems I'm finding.
#17

[eluser]hugle[/eluser]
[quote author="MrCevic" date="1272487877"]Hi Phil, I've just updated my question with more information on how I'm using your library and the problems I'm finding.[/quote]

I had similar problems as yours...
I have made some modifications to template.php library earlier...

Could you try my attached file and see if it helped you?


Btw.

When you are setiing up layout as layout.php
you should later use: build('index.php') for example

and the content of 'build' you can get by:

putting: &lt;?php echo $template['body'];?&gt; in layout.php...

Just play with it, see PyroCMS examples Smile
#18

[eluser]MrCevic[/eluser]
Hi Hugle,

I tried the library but it didn't solve my problem. I'm still getting the "Unable to locate the file: layout.php" error.

I'm using "&lt;?php echo $template['body'];?&gt;" in my template as you can see from the description of my setup above. I also tried to replace "layout" with "index.php" in $this->template->build('layout', $data); but get the same error "Unable to locate the file: index.php"
#19

[eluser]Phil Sturgeon[/eluser]
The newest version has changed to store layout files in:

Quote:application/themes/default/views/layouts/default.php

Probably should have mentioned that to somebody at some point...
#20

[eluser]MrCevic[/eluser]
Hi Phil,

I don't know if your last reply referred to my post. Just in case I

1- went and created a "layouts" folder in "application/themes/default/views"
2- placed inside a copy of my "layout.php" and renamed it "default.php"
3- tried to run the code as it was and also modifying the controller "welcome.php" from "$this->template->build('layout', $data);" to "$this->template->build('default', $data);"

but I'm still getting the "Unable to locate the file: default.php (or template.php)"




Theme © iAndrew 2016 - Forum software by © MyBB