Share » Forums » Developer » Can I access the Content Module API...

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

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

Sunday 27 February 2005 2:00:33 pm - 5 replies

Author Message

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

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu