Pergunta

I've got a php file with a function in it which gets a list of items from a source file and then formats that list with some html. At the end, it returns a var ($html) containing the html formatted list.

What I'd like to know how to do is return this html formatted list to a content article, so it can be displayed in an article. I have several different articles wherein I'd like to display this list. So, what I'd like is to be able to write the content for each article and then, at some point in the article, display the list using a function call of some kind. I just don't know how to do this.

I should note that I'm using Joomla 1.5 (yeah, I know... it's completely out of my hands). I looked into adding plugins which would allow me to write php code right in a content article but there are two problems with that: 1) those plugins don't work with Joomla 1.5 and 2) Then I'd have to maintain the same code in several different articles.

Ideally, I should just be able to write {ShowList} (or whatever) somewhere in my article and have it display the list.

How can this be done?

WATYF

Foi útil?

Solução

You could create a content plugin that incorporates your existing function. A content plugin simply looks for a string (e.g. {showlist}) and replaces it with what ever it defined to replace it with.

For an example look at the LoadModule content plugin in /plugins/content/ — specifically the two files that make up the plugin. loadmodule.php and loadmodule.xml.

That plugin looks for the strings {loadposition} in response to an onPrepareContent event and replaces it with the output of the module assigned to that position.

You can read about plugins and creating plugins on the Joomla! docs website. Please note that plugins haven't changed that much since 1.5, mostly it is just the event names that have changed, but you can check against the core 1.5 plugins for those details.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top