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

[eluser]Phil Sturgeon[/eluser]
[quote author="MrCevic" date="1272573254"]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)"[/quote]

I was talking to you yes but it depends what version of the templatel ibrary you are using.

Whichever version you are using you have the fundamentals wrong.

A "layout" acts like a wrapper around a view. You are padding the layout name in where the view should be!

Code:
$this->template->set_layout('default');
$this->template->build('someview', $data);

The set_layout() should go in some global code like a hook or MY_Controller so it is done everywhere, or you can just place it in each Controller constructor if you are feeling lazy.
#22

[eluser]MrCevic[/eluser]
I believe I have the last version as I downloaded the library three days ago and I see the last modified version from 24th March 2010 (I don't know if this helps but the file is called philsturgeon-codeigniter-template-6a0ce15).

As you can see from my post (http://ellislab.com/forums/viewthread/14...10/#743743) I did create a MY_Controller 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');
    }
}
?>

Which part of this is wrong?

Also, as I explained in my first post, I created a themes file structure as you recommend:

Quote:system/application/themes/default/views/

and inside I placed a file "layout.php" with 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;

And then my controller "welcome.php" has the following code:
Code:
&lt;?php
class Welcome extends Controller {

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

What you suggest is that I should have a view file (say "welcome.php") in the view folder which will display the content sent from the controller?
#23

[eluser]liri[/eluser]
Hey MrCevic,

I'm trying to implement it too to no avail though I think your problem is pretty obvious
while mine is rather still vague.

In your Welcome controller, aren't you supposed to extend MY_Controller
rather than Controller? I think I spotted that on someone else's error as well.


I'll elaborate on my issue in another reply for the sake of clarity.
#24

[eluser]hugle[/eluser]
[quote author="liri" date="1272595544"]Hey MrCevic,

I'm trying to implement it too to no avail though I think your problem is pretty obvious
while mine is rather still vague.

In your Welcome controller, aren't you supposed to extend MY_Controller
rather than Controller? I think I spotted that on someone else's error as well.


I'll elaborate on my issue in another reply for the sake of clarity.[/quote]

Hello,


just try:

Code:
$this->template->build('layout', $data);
replace with:
$this->template->build('welcome');

and create view welcome.php
and put text in it:
'this is welcome.php'

and see what happens ...

good luck
#25

[eluser]MrCevic[/eluser]
Well, I did try to use "MY_Controller" instead of "Controller" and it didn't make it better.

I'm sure that there are some obvious things that I'm doing wrong and maybe that explains why this library doesn't work for me. I tried to understand and implement the only documentation I read about this library (http://philsturgeon.co.uk/code/codeigniter-template) and I published exactly what I did in my first post. The only thing I'd like to have is a more precise answer to what I'm doing wrong. If I can get the library to work I don't mind writing a more thorough documentation. In the meantime I think I'll try another template library.

By the way, I tried http://www.williamsconcepts.com/ci/codei...s/template and managed to make it worked in a minute.
#26

[eluser]Phil Sturgeon[/eluser]
Somebody put together a wiki page.

http://codeigniter.com/wiki/codeigniter-template/
#27

[eluser]liri[/eluser]
Oh, odd.
I've put that up and I also remember posting to this forum about it...
No idea what went wrong, maybe session ended or something and it didn't go through.

Anyway, yeah, I'm planing to put up wiki pages for some of Phil's libraries with documentation
and examples on how to use them as they are true gems, though indeed lack documentation to get
a novice started.


Regards,
Liran.
#28

[eluser]MrCevic[/eluser]
Thanks Liri! After reading your wiki page and the documentation available at http://www.williamsconcepts.com/ci/codei...s/template I was able to get Phil's template library to work. The MY_Controller approach doesn't work for me, so I just decided to load the template library using "system/application/config/autoload.php" which for me makes sense as I will be using templates with all my controllers.
#29

[eluser]umefarooq[/eluser]
Hi Phil i have one question with you Dwoo template parser in main layout i have one variable {$template.body} to show the body of the layout but there is another variable in that body which is not getting parsed if i use $template['body'] then second variable in the body section is getting parsed but if im using $template.body then second variable is showing as it is e.g {$test} any solution for this.
#30

[eluser]liri[/eluser]
[quote author="MrCevic" date="1272855464"]Thanks Liri! After reading your wiki page and the documentation available at http://www.williamsconcepts.com/ci/codei...s/template I was able to get Phil's template library to work. The MY_Controller approach doesn't work for me, so I just decided to load the template library using "system/application/config/autoload.php" which for me makes sense as I will be using templates with all my controllers.[/quote]

ֹAhh, you ofcourse need to load the library, I also put it on autoload (makes sense too).
I'll add this to the example.


Regards,
Liran.




Theme © iAndrew 2016 - Forum software by © MyBB