Welcome Guest, Not a member yet? Register   Sign In
Template Library Version 1.4
#31

[eluser]newsun[/eluser]
We ended up doing a str_replace in this case as mentioned and will probably just add this method into the Template library on our end as it's something that will get used often...I think it would be minimal overhead to have a method available as part of the install and it allows more flexibility
It could simply be: parse_string or write_string, or just a boolean trigger in the write or write_view methods

Here is basically what we added:

Code:
function parse_string($string, $array) {
        
    foreach ($array as $key => $value) {
        $string = str_replace('<?=$'.$key.'?>', $value, $string);
    }
        
    return $string;
    
}

As to my other question, you basically answered it. What I think would beneficial would be a concise list of the additional features Template offers over built in view. I saw three main ones and that is what I listed.


Also what is the purpose of making regions manditory to be defined? Is it for speed based on the length of array which is looped through? To avoid having to search for a region in the file which might not exist, this gets done if there is a region defined anyhow, right?
#32

[eluser]Colin Williams[/eluser]
Quote:Also what is the purpose of making regions manditory to be defined?

Hrm.. mainly to keep the API solid. I went back and forth on it but settled on making it strict. Imagine writing to a region but misspelling the region name. The contents would essentially be lost. Feel free to call that reason dumb, but that is the reason Smile
#33

[eluser]newsun[/eluser]
[quote author="Colin Williams" date="1221127654"]
Quote:Also what is the purpose of making regions manditory to be defined?

Hrm.. mainly to keep the API solid. I went back and forth on it but settled on making it strict. Imagine writing to a region but misspelling the region name. The contents would essentially be lost. Feel free to call that reason dumb, but that is the reason Smile[/quote]

Seems like throwing an error would suffice (isn't this what happens now?), perhaps an option to send an admin email or a log set in the config if desired. Only reason I say this is that it makes setup harder with no perceived benefit to me.

And yeah imagine now having one less place to be able to do said misspelling Wink
#34

[eluser]M4rc0[/eluser]
Hi there,

First, Thanks for this amazing library, it's fantastic :cheese:
I always had a step behind codeigniter for it's lack (or poor) use of template until i met this library. Thanks for sharing!

Now, i'm having some learning curve here. Since i'm new to CodeIgniter, this might not be a Template problem, i apologize if that is the case Tongue

My problem is the following:
From the three Template installation files, i have done my own template.php that lies in application/view/template.php and the rest is intact.
The config file i didn't change at all (just added a region) and of course, the library file is intact as well.
So all this should work all of the box correct?

I have a home controller (default controller on routes.php) with the code:
Code:
(...)
function index()
{
  $this->template->render();
}
function hello()
{
  echo "I'm here";
  $this->template->render();
}

Now if i go to "mysite.com/", i'll see the template beautifully set, thus showing that index is working.

But, if i go to "mysite.com/index.php/home/" it won't work, and "index.php/home/hello" won't work either (but it will show the echo).

Am i missing something obvious? Something in routes maybe?

Because it only worked for the default controller/class specified on routes.php.

The funny thing is that the echo shows and if i click to view source the template.php is there!

And question: do i have to do $this->template->render(); in every function?
#35

[eluser]Colin Williams[/eluser]
Quote:The funny thing is that the echo shows and if i click to view source the template.php is there!

Do you mean the parsed code is there or the raw PHP code? If it's the latter, there might be something whacky with your PHP interpreter.

Quote:And question: do i have to do $this->template->render(); in every function?

Not necessarily, but typically, yes. Sometimes I make use of the _remap() controller function, which runs some logic based on the proper method to call, then calls render(). So, all the other functions are doing is manipulating the template. It has to be called at some point in execution though.
#36

[eluser]M4rc0[/eluser]
[quote author="Colin Williams" date="1221272031"]
Do you mean the parsed code is there or the raw PHP code? If it's the latter, there might be something whacky with your PHP interpreter.[/quote]
The xhtml haha. PHP would be very whacky indeed.

So the whole code is there on view source. But it shows like there is no loaded css files: ugly lists, white background, blue links..

Thinking of it, maybe it's CSS? But then how come the root site works?
Code:
<link rel="stylesheet" type="text/css" href="public/stylesheets/screen.css" />
<link rel="stylesheet" type="text/css" href="public/stylesheets/custom.css" />
Yes i have that path correct. The template is loading when i don't specify controller/function/id in the URI.

Quote:Sometimes I make use of the _remap() controller function, which runs some logic based on the proper method to call, then calls render(). So, all the other functions are doing is manipulating the template. It has to be called at some point in execution though.

wowow slow down. I tought i made myself clear that i'm newbie :wow:
_remap() what's that? i didn't understand much of what you just said Tongue
#37

[eluser]Colin Williams[/eluser]
_remap() is a special method you can provide in a controller. When provided, that method is ALWAYS called regardless of the other URI segments. This is a way to do advanced routing within a given controller. (Check the User Guide for more details.)

Quote:Thinking of it, maybe it’s CSS? But then how come the root site works?

You're using relative paths to call your CSS. This means relative to the URI. So if the URI is http://www.example.com, you'll get http://www.example.com/public/stylesheets/custom.css

But..

When you're at http://www.example.com/index.php/hello, the browser will now be requesting http://www.example.com/index.php/hello/p...custom.css

Obviously, that's a problem Smile
#38

[eluser]M4rc0[/eluser]
Thanks for the _remap() tip.
So if i put template_render there, can i remove the template_render method from all functions within a controller?
Looks a lot better to me.

And yes, it was the absolute path problem Tongue
Funny i was typing and got the idea. I don't like absolute paths, when i change host i will have to change there again.
What's the correct way to concatenate with base_url() ? I couldn't do it.

Thanks Colin Smile
#39

[eluser]steelaz[/eluser]
I usually place
Code:
<base href="<?= base_url() ?>" />
in my header, before including any file. Then I can use relative paths for includes, images etc.
Code:
<link rel="stylesheet" type="text/css" href="assets/css/main.css">
Works very well when moving site, I just need to change base_url in config.
#40

[eluser]M4rc0[/eluser]
[quote author="steelaz" date="1221327082"]I usually place
Code:
<base href="<?= base_url() ?>" />
in my header, before including any file. Then I can use relative paths for includes, images etc.
Code:
<link rel="stylesheet" type="text/css" href="assets/css/main.css">
Works very well when moving site, I just need to change base_url in config.[/quote]

Your tip looks very good steelaz, but it didn't work for me.

So you're saying the usage would be something like this:
Code:
<head>
<base href="<?=base_url()?>"
<link rel="stylesheet" type="text/css" href="assets/css/main.css" />
</head>

You sure that base tag works?




Theme © iAndrew 2016 - Forum software by © MyBB