Welcome Guest, Not a member yet? Register   Sign In
Extending the Templating class
#1

[eluser]MaartenDeGroote[/eluser]
Hi everybody,

I want to use some form of templating system, but also don't want to rely on larger templating classes like Smarty. Therefore CI's own templating class suits my needs, **almost** that is...

What I am looking for is a way to control the number of loops via pseudo-variables. Let's say there's a construction like the one below
Code:
{blog_entries}
  {title}
  {body}
{/blog_entries}

Is there a way to make sure the template designer can control the number of loops within the view? Maybe something like this to show only the first 10 posts.

Code:
{blog_entries:10}
  {title}
  {body}
{/blog_entries}

Can this be achieved within CI's templating class without having to tweak it too much?

Thanx for your replies!
#2

[eluser]Basketcasesoftware[/eluser]
The code within CI's Template class is pretty simple. You can certainly extend it but in your case I'd just control the number of loops by limiting the size of the array you send it. It's a good idea though. If you could do this extension to do more than just limit the count. How about starting position and count as an option? Right now that class just uses a simple foreach loop if I recall correctly.
#3

[eluser]MaartenDeGroote[/eluser]
Alrighty,

But where should I start? Do I have to get into the code in System/Libraries/Parser.php and start editing this? Or could I just make an own library that extends the Parser?

Anyhow, I'm pretty sure I will have to dive into regular expressions and stuff and that's just not my thing...

Is there anyone out there who could give me a jump-start with this one Smile ?
#4

[eluser]InsiteFX[/eluser]
You create a new MY_Parser class

application/libraries/MY_Parser.php
Code:
class MY_Parser extends CI_Parser {

}

InsiteFX
#5

[eluser]MaartenDeGroote[/eluser]
Ok thanx. Could you also point me in the direction of the regular expression I have to use?

Let's say I would want to use the following construction (where offset/count are optional):
Code:
{blog_entries:offet:count}
  {title}
  {body}
{/blog_entries}

How can I catch this with an expression?
#6

[eluser]InsiteFX[/eluser]
For regular expressions here is great utility for figuring them out!

Regular Expression Tester

Look on the bottom right hand side and you can download a desktop version to run on your system!

InsiteFX
#7

[eluser]Basketcasesoftware[/eluser]
@InsiteFX - Oh! Sweet!




Theme © iAndrew 2016 - Forum software by © MyBB