tags:

views:

66

answers:

2

I'm trying to get a small set of php functions working that i need available on the entire page. I'm including them in my index.php main template via require_once "my_functions.php".

They work in the index.php template; that's the good news.

We have a plugin that let's us write php in our content items with the following syntax: {source}<?php echo "hello world!"; ?>{/source}

However, when trying to use the functions defined in my_funcitons.php, php thinks they're unavailable and generates a fatal error ... undefined method or function.

Any ideas?

A: 

Try using Direct PHP.

Colour Blend
if i use `require_once "my_functions.php"` in the content pages it will work.This is not really a solution though because the functions are also needed in the main index.php file.I don't want to include them twice or be forced to include them in every single content item.
macek
+2  A: 

I do believe you should write a module, implement your require_once inside it and insert the created module in articles.

Avoid creating too much php code in WYSIWYG editors, you're mixing content with programming logic, defeating CMS's purpose: manage content. And if you have non-technical people behind your system this can become a real headache in the future.

GmonC
Alternatively, you can create content plugins for each of the features you're trying to incorporate, then have those plugins scan the article for tokens that you replace with markup: http://docs.joomla.org/How_to_create_a_content_plugin
jlleblanc
Yeah, I forgot he could use some plugins too. It's a good approach too, thanks!
GmonC