|
While looking for this, I was a bit confused because of the several different queries that I came up with. Queries such as "How to display a component's output", or "How to get article's body" have the same goal; extract an article's body (i.e. the content of an article) without all that code that Joomla! generates (menu, header, logo, footer, sidebars etc.).
The most obvious reason for this is to take the content of an article and place it somewhere else than the main content area.
This is similar to the index2.php functionality, which is depreciated since 1.5.
The functionality of index2.php was applied to components in general, and not only to articles. This one seems to do exactly the same (due to the "component" parameter), but I haven't tested it yet.
So, let's get to the juice and see how to extract the content of an article and use it somewhere else...
- Create a new article (or copy an existing one).
- Create a new menu item and link to the article (select Article Layout in the Menu Item Type dialog).
- Copy the URL that Joomla! generates from the
Link field.

- Add the
tmpl=component parameter to the end of the URL, using the concatenation symbol. Example: index.php?option=com_content&view=article&id=1&tmpl=component
- You're done.
Notes
- The menu item is created in order to create/get the URL that leads to your article. If you don't want it to be shown in any menu, then create another menu which will not be published, and place it in there. DON'T DELETE IT NOR DISABLE IT otherwise the link won't work.
- If you have SEO enabled you can use the generated link by replacing all the above path with
article.html?&tmpl=component The article.html portion of the above URL depends on the alias of the article (the article part in this example) and the SEO settings you have set (the .html part in this example). Use whatever applies to you.
- The id value has to be same as the article id that you want. You can find it on the right-hand side in the list of articles, as shown in the screenshot below.

- You can add additional parameters to this link, if required, using the concatenation symbol and following the
variable=value format. e.g. index.php/article.html?&tmpl=component&id=1&var1=val1&var2=val2
- In order to get only the body of the article, you have to disable the options for showing author, title, date, etc. otherwise, these will be shown as well.
Now, why don't we take this a step further and use an AJAX call to update the contents of an HTML element (div, p, table, etc.) with our article...?
|
This is exactly what I needed!