Helpers?

5 views
Skip to first unread message

John O.

unread,
Apr 13, 2010, 10:49:45 AM4/13/10
to php-outline
Could you please give some information on how to define helpers in a
template?
I once stumbled upon them by accident but now no longer know how to do
it.
Your documentation only mentions that they exist.

I want to create new template tags that query the database.
That way I could let the user of the script define their own database
query in the template without the need of editing anything else but
the template.

Such a tag could look something like this:
{database variable=$test
table=tablename
where='id=123'
limit=1
order='id'}

Afterwards the user would use the variable $test to access the
content.

Maybe those helpers could help me do what I want to do?

John O.

unread,
Apr 13, 2010, 1:43:11 PM4/13/10
to php-outline
I found what I was looking for: the custom user functions.
You really did an amazing job with this template engine. :-)

mindplay.dk

unread,
Apr 15, 2010, 11:08:14 AM4/15/10
to php-outline
Thank You :-)

Yeah, helpers are something different - they were implemented as a
means to support a form builder, which I never finished. I discovered
that this was entirely the wrong way to go about that, so this feature
will not be documented, and in Outline 2.0, this feature has been
removed.

By the way, I would recommend you read up on MVC principles - Outline
was designed as a means to simplify generation of view templates. As
you've discovered, however, I made no attempts to enforce MVC
principles, that's up to the developer - building something like a
database query into a view is a sure way to get your model/controller
logic tangled up in your view code.

If this the first template engine you've worked with, you're probably
tempted to try to wrap up all of your code in little reusable
commands. This is both good and bad. Good because you're having an
important realization for any programmer to have at some point - that
lazyness is a virtue. But bad because you're going about it all wrong
- your database logic has no business floating around in your
templates.

As time goes on, you will realize that while you're apparently making
fast progress ("wow, look, I did this query and printed out the result
with one line of code!") the long term result is unmaintainable messy
spaghetti code.

Why?

Read up on the principles of MVC development.

You'll thank me later :-)

John O.

unread,
May 15, 2010, 5:12:34 AM5/15/10
to php-outline
Thanks for the reply.

I know that one should not add logic to the views.
But once my application is released, there will be parts that I can no
longer make changes in update releases (like for example the database
or the templates).
Keeping those parts to a minimum is what I aim for. So adding database
queries to the templates will allow me to later change the controller
without having to worry that I break things in the templates.

I haven't fully decided if I go through with it.
But the other option is not having a router class and a single index
file and instead adding lots and lots of individual php files that
produce the output. That's just about as difficult to manage as the
spaghetti code database queries in the template plugins.

--
To unsubscribe from the "php-outline" group, send email to:
php-outline...@googlegroups.com

To browse discussions or post to the group, go here:
http://groups.google.com/group/php-outline?hl=en

To obtain the software and study the documentation, go here:
http://code.google.com/p/php-outline/
Reply all
Reply to author
Forward
0 new messages