Forums / Developer / Can I access the Content Module API directly, bypass templates??

Can I access the Content Module API directly, bypass templates??

Author Message

Aldo Bucchi

Sunday 27 February 2005 2:00:33 pm

I believe that eZp has it right in terms of usability, but I have to admit that the proprietary templating paradigm imposed by eZp has been the main deterrant for using it for major developments, where the content repository must be accessed and published in a flexible manner (ie not just websites).

If I could just access the contentmodule api directly (as a standalone content repository)... that would allow for absolute flexibility! Forgetting about templates, just use your own PHP or whatever to render the content.

Seriously, this has been a problem with many many projects.

Maybe create a hook in index.php to bypass the templating module calls, just after bootstrapping has set up the necessary environment.

Paul Forsyth

Sunday 27 February 2005 2:55:36 pm

You can do this right now, depending on what you need of course ;)

What do you need to do?

paul

Aldo Bucchi

Sunday 27 February 2005 3:58:00 pm

hi paul,

Basically I want to render my webpages with PHP (no templates).
I have no need for a separation of concerns so templating becomes more of a a problem rather than a solution.
Besides, I need some funcionality that is impossible (or unnecessarily difficult) to implement within the constraints of the templating system or by extending it (RSS, Custom XML Feeds for Flash and Mobiles, XForms, ATOM, etc).

There should be a way to access the environment variables (user, uri, active node, etc) and the modules just by coding a hook some point in index.php . but of course it depends on the nature and inner workings of the system and the bootstrapping... which I don't know.

is this documented?
Any hints?, working code?

What about the caching mechanism... is it intrinsically ligated to templating??
Can I access utilities sucha as URL rendering?? how??
etc
etc

Best regards,
Aldo

Paul Forsyth

Monday 28 February 2005 1:40:13 am

The really simple way to do this right now is to create your own module/view. A small module is simple to add.

If you have a look at any view you'll find code like the following at the end of the view.

$tpl =& templateInit();
$tpl->setVariable( 'login', $userLogin, 'User' );
$Result['content'] =& $tpl->fetch( 'design:user/login.tpl' )

The setup code is simple enough. The bit you are likely interested in is the fetch call. This invokes the template mechanism to pull in the right override. The value returned is just a string containing html for the browser to display. So, if you include your php files at this point the content field is populated.

This helps to populate the template variable $module_result. In the above example the html is stored in $module_result.content. This is rendered in the pagelayout.tpl you are using. Still a template of course so you can either have a blank pagelayout.tpl with only a

{$module_result.content}

call, or you can enter surrounding text which utilises other template features such as nodes and url_aliases, before including your 'content' as the body for the page. It all depends on your needs.

If you do want to obtain other ez features from your own php then you have to utilise the api directly with your php. But at least at this point you have an entry point from which to work.

Does this help?

Paul

Paul Forsyth

Monday 28 February 2005 1:43:28 am

The caching mechanism is based on templates.

If you follow my method of using pagelayout.tpl you obtain this benefit. Simple create a {cache-block} around your module result and it should be catered for.

paul

Aldo Bucchi

Monday 28 February 2005 10:36:30 am

Paul,

That's certainly a very good start... sounds pretty straightforward.
So, I'll be going over the module documentation this week and give it a try.
I'll be posting my findings / questions.

Many thanks for your help,
Cheers
Aldo